From: Robert Griesemer Date: Wed, 16 Dec 2009 02:03:59 +0000 (-0800) Subject: Fix for scanner bug (introduced with most recent change). X-Git-Tag: weekly.2009-12-22~40 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a47a45ec7741d677ea6582cdeee3419325ac9488;p=gostls13.git Fix for scanner bug (introduced with most recent change). Fixes #433. R=rsc CC=golang-dev https://golang.org/cl/179072 --- diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index fad3c0f754..4735cbd3b5 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 6ea4b2d58e..83314a3aa1 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", }