bc998d034f
Reviewed-on: https://go-review.googlesource.com/63753 From-SVN: r252767
39 lines
737 B
Go
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: }
|
|
}
|