Created
December 4, 2017 22:31
-
-
Save campoy/338870a69acc90fe48a33a519fecbfa6 to your computer and use it in GitHub Desktop.
Code snippets for https://medium.com/@francesc/whats-the-most-common-identifier-in-go-s-stdlib-e468f3c9c7d9 Raw Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs := token.NewFileSet() | |
for _, arg := range os.Args[1:] { | |
b, err := ioutil.ReadFile(arg) | |
if err != nil { | |
log.Fatal(err) | |
} | |
f := fs.AddFile(arg, fs.Base(), len(b)) | |
var s scanner.Scanner | |
s.Init(f, b, nil, scanner.ScanComments) | |
for { | |
_, tok, lit := s.Scan() | |
if tok == token.EOF { | |
break | |
} | |
fmt.Println(tok, lit) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment