]> Cypherpunks repositories - gostls13.git/commitdiff
text/scanner: use correct token position in example
authorRobert Griesemer <gri@golang.org>
Fri, 12 May 2017 18:58:09 +0000 (11:58 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 12 May 2017 19:45:59 +0000 (19:45 +0000)
While at it, unindent source text so column values are easier
to read, remove unnecessary text in output, and simplify the
loop.

Fixes #20346.

Change-Id: I0fde02b9e4242383da427f4cf4c6c13dd0ab3b47
Reviewed-on: https://go-review.googlesource.com/43450
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/text/scanner/example_test.go

index 1d5d34a01526277502af3b34cb37ad6732519264..97e22a98f4155e02b80853978af25723b53d4331 100644 (file)
@@ -12,28 +12,25 @@ import (
 
 func Example() {
        const src = `
-       // This is scanned code.
-       if a > 10 {
-               someParsable = text
-       }`
+// This is scanned code.
+if a > 10 {
+       someParsable = text
+}`
        var s scanner.Scanner
-       s.Filename = "example"
        s.Init(strings.NewReader(src))
-       var tok rune
-       for tok != scanner.EOF {
-               tok = s.Scan()
-               fmt.Println("At position", s.Pos(), ":", s.TokenText())
+       s.Filename = "example"
+       for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() {
+               fmt.Printf("%s: %s\n", s.Position, s.TokenText())
        }
 
        // Output:
-       // At position example:3:4 : if
-       // At position example:3:6 : a
-       // At position example:3:8 : >
-       // At position example:3:11 : 10
-       // At position example:3:13 : {
-       // At position example:4:15 : someParsable
-       // At position example:4:17 : =
-       // At position example:4:22 : text
-       // At position example:5:3 : }
-       // At position example:5:3 :
+       // 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: }
 }