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.Init(strings.NewReader(src)) 21 var tok rune 22 for tok != scanner.EOF { 23 tok = s.Scan() 24 fmt.Println("At position", s.Pos(), ":", s.TokenText()) 25 } 26 27 // Output: 28 // At position 3:4 : if 29 // At position 3:6 : a 30 // At position 3:8 : > 31 // At position 3:11 : 10 32 // At position 3:13 : { 33 // At position 4:15 : someParsable 34 // At position 4:17 : = 35 // At position 4:22 : text 36 // At position 5:3 : } 37 // At position 5:3 : 38 } 39