Skip to content

Instantly share code, notes, and snippets.

@campoy
Created December 4, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save campoy/338870a69acc90fe48a33a519fecbfa6 to your computer and use it in GitHub Desktop.
Save campoy/338870a69acc90fe48a33a519fecbfa6 to your computer and use it in GitHub Desktop.
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