Source file
src/go/scanner/example_test.go
1
2
3
4
5 package scanner_test
6
7 import (
8 "fmt"
9 "go/scanner"
10 "go/token"
11 )
12
13 func ExampleScanner_Scan() {
14
15 src := []byte("cos(x) + 1i*sin(x) // Euler")
16
17
18 var s scanner.Scanner
19 fset := token.NewFileSet()
20 file := fset.AddFile("", fset.Base(), len(src))
21 s.Init(file, src, nil , scanner.ScanComments)
22
23
24 for {
25 pos, tok, lit := s.Scan()
26 if tok == token.EOF {
27 break
28 }
29 fmt.Printf("%s\t%s\t%q\n", fset.Position(pos), tok, lit)
30 }
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 }
47
View as plain text