Implemented goScanner.go
This commit is contained in:
parent
fc7b063254
commit
8ba8b75b48
2 changed files with 29 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,36 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"go/scanner"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 1 {
|
||||
fmt.Println("Not enough arguments!")
|
||||
return
|
||||
}
|
||||
|
||||
for _, file := range os.Args[1:] {
|
||||
fmt.Println("Processing:", file)
|
||||
f, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
one := token.NewFileSet()
|
||||
files := one.AddFile(file, one.Base(), len(f))
|
||||
|
||||
var myScanner scanner.Scanner
|
||||
myScanner.Init(files, f, nil, scanner.ScanComments)
|
||||
|
||||
for {
|
||||
pos, tok, lit := myScanner.Scan()
|
||||
if tok == token.EOF {
|
||||
break
|
||||
}
|
||||
fmt.Printf("%s\t%s\t%q\n", one.Position(pos), tok, lit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue