github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/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 // +build ignore 6 7 package scanner_test 8 9 import ( 10 "fmt" 11 "strings" 12 "text/scanner" 13 ) 14 15 func Example() { 16 const src = ` 17 // This is scanned code. 18 if a > 10 { 19 someParsable = text 20 }` 21 var s scanner.Scanner 22 s.Init(strings.NewReader(src)) 23 var tok rune 24 for tok != scanner.EOF { 25 tok = s.Scan() 26 fmt.Println("At position", s.Pos(), ":", s.TokenText()) 27 } 28 29 // Output: 30 // At position 3:4 : if 31 // At position 3:6 : a 32 // At position 3:8 : > 33 // At position 3:11 : 10 34 // At position 3:13 : { 35 // At position 4:15 : someParsable 36 // At position 4:17 : = 37 // At position 4:22 : text 38 // At position 5:3 : } 39 // At position 5:3 : 40 }