diff options
| author | Robert Griesemer <gri@golang.org> | 2009-12-15 18:03:59 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2009-12-15 18:03:59 -0800 |
| commit | 75d3ba0eecd2fdc9137e55436f88d0671beb37a5 (patch) | |
| tree | 2172d767fa9a1c7dee33313a884b804d792deea4 /src/pkg/go | |
| parent | a2a47b1d89a5bc4682fadb95a8d432412c0ed11e (diff) | |
| download | golang-75d3ba0eecd2fdc9137e55436f88d0671beb37a5.tar.gz | |
Fix for scanner bug (introduced with most recent change).
Fixes issue 433.
R=rsc
CC=golang-dev
http://codereview.appspot.com/179072
Diffstat (limited to 'src/pkg/go')
| -rw-r--r-- | src/pkg/go/scanner/scanner.go | 8 | ||||
| -rw-r--r-- | src/pkg/go/scanner/scanner_test.go | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index fad3c0f75..4735cbd3b 100644 --- a/src/pkg/go/scanner/scanner.go +++ b/src/pkg/go/scanner/scanner.go @@ -223,10 +223,10 @@ func (S *Scanner) findNewline(pos token.Position) bool { } } - // reset position + // reset position to where it was upon calling findNewline S.pos = pos S.offset = pos.Offset + 1 - S.ch = '/' + S.next() return newline } @@ -577,6 +577,10 @@ scanAgain: if S.ch == '/' || S.ch == '*' { // comment if S.insertSemi && S.findNewline(pos) { + // reset position to the beginning of the comment + S.pos = pos + S.offset = pos.Offset + 1 + S.ch = '/' S.insertSemi = false // newline consumed return pos, token.SEMICOLON, semicolon } diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go index 6ea4b2d58..83314a3aa 100644 --- a/src/pkg/go/scanner/scanner_test.go +++ b/src/pkg/go/scanner/scanner_test.go @@ -392,6 +392,8 @@ var lines = []string{ "foo $/*comment*/ \n", "foo $/*0*/ /*1*/ /*2*/ \n", "foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa", + + "package main$\n\nfunc main() {\n\tif {\n\t\treturn /* */ }$\n}$\n", } |
