gcc/libgo/go/text/scanner/example_test.go
Ian Lance Taylor bc998d034f libgo: update to go1.9
Reviewed-on: https://go-review.googlesource.com/63753

From-SVN: r252767
2017-09-14 17:11:35 +00:00

39 lines
737 B
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package scanner_test
import (
"fmt"
"strings"
"text/scanner"
)
func Example() {
const src = `
// This is scanned code.
if a > 10 {
someParsable = text
}`
var s scanner.Scanner
s.Init(strings.NewReader(src))
s.Filename = "example"
for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() {
fmt.Printf("%s: %s\n", s.Position, s.TokenText())
}
// Output:
// example:3:1: if
// example:3:4: a
// example:3:6: >
// example:3:8: 10
// example:3:11: {
// example:4:2: someParsable
// example:4:15: =
// example:4:17: text
// example:5:1: }
}