Commit a47a45ec authored by Robert Griesemer's avatar Robert Griesemer

Fix for scanner bug (introduced with most recent change).

Fixes #433.

R=rsc
CC=golang-dev
https://golang.org/cl/179072
parent 69bed164
...@@ -223,10 +223,10 @@ func (S *Scanner) findNewline(pos token.Position) bool { ...@@ -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.pos = pos
S.offset = pos.Offset + 1 S.offset = pos.Offset + 1
S.ch = '/' S.next()
return newline return newline
} }
...@@ -577,6 +577,10 @@ scanAgain: ...@@ -577,6 +577,10 @@ scanAgain:
if S.ch == '/' || S.ch == '*' { if S.ch == '/' || S.ch == '*' {
// comment // comment
if S.insertSemi && S.findNewline(pos) { 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 S.insertSemi = false // newline consumed
return pos, token.SEMICOLON, semicolon return pos, token.SEMICOLON, semicolon
} }
......
...@@ -392,6 +392,8 @@ var lines = []string{ ...@@ -392,6 +392,8 @@ var lines = []string{
"foo $/*comment*/ \n", "foo $/*comment*/ \n",
"foo $/*0*/ /*1*/ /*2*/ \n", "foo $/*0*/ /*1*/ /*2*/ \n",
"foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa", "foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa",
"package main$\n\nfunc main() {\n\tif {\n\t\treturn /* */ }$\n}$\n",
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment