github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/src/text/scanner/example_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package scanner_test 6 7 import ( 8 "fmt" 9 "strings" 10 "text/scanner" 11 ) 12 13 func Example() { 14 const src = ` 15 // This is scanned code. 16 if a > 10 { 17 someParsable = text 18 }` 19 var s scanner.Scanner 20 s.Filename = "example" 21 s.Init(strings.NewReader(src)) 22 var tok rune 23 for tok != scanner.EOF { 24 tok = s.Scan() 25 fmt.Println("At position", s.Pos(), ":", s.TokenText()) 26 } 27 28 // Output: 29 // At position example:3:4 : if 30 // At position example:3:6 : a 31 // At position example:3:8 : > 32 // At position example:3:11 : 10 33 // At position example:3:13 : { 34 // At position example:4:15 : someParsable 35 // At position example:4:17 : = 36 // At position example:4:22 : text 37 // At position example:5:3 : } 38 // At position example:5:3 : 39 }