gcc/ChangeLog:
[official-gcc.git] / libgo / go / text / scanner / example_test.go
blobf8b51b7322b0a8ab8a7034e15e45d698dfaadedd
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.
5 // +build ignore
7 package scanner_test
9 import (
10 "fmt"
11 "strings"
12 "text/scanner"
15 func Example() {
16 const src = `
17 // This is scanned code.
18 if a > 10 {
19 someParsable = text
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())
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 :