Commit 3a50d721 authored by Robert Griesemer's avatar Robert Griesemer

go/scanner: line comments may end in EOF

R=rsc
CC=golang-dev
https://golang.org/cl/2908041
parent 132e5435
...@@ -183,20 +183,17 @@ func (S *Scanner) scanComment() { ...@@ -183,20 +183,17 @@ func (S *Scanner) scanComment() {
if S.ch == '/' { if S.ch == '/' {
//-style comment //-style comment
for S.ch >= 0 {
S.next() S.next()
if S.ch == '\n' { for S.ch != '\n' && S.ch >= 0 {
// '\n' is not part of the comment for purposes of scanning S.next()
// (the comment ends on the same line where it started) }
if col == 1 { if col == 1 {
// comment starts at the beginning of the current line // comment starts at the beginning of the current line
S.interpretLineComment(S.src[offs:S.offset]) S.interpretLineComment(S.src[offs:S.offset])
} }
return return
} }
}
} else {
/*-style comment */ /*-style comment */
S.next() S.next()
for S.ch >= 0 { for S.ch >= 0 {
...@@ -207,7 +204,6 @@ func (S *Scanner) scanComment() { ...@@ -207,7 +204,6 @@ func (S *Scanner) scanComment() {
return return
} }
} }
}
S.errorAt(pos, "comment not terminated") S.errorAt(pos, "comment not terminated")
} }
......
...@@ -395,12 +395,14 @@ var lines = []string{ ...@@ -395,12 +395,14 @@ var lines = []string{
"var\n", "var\n",
"foo$//comment\n", "foo$//comment\n",
"foo$//comment",
"foo$/*comment*/\n", "foo$/*comment*/\n",
"foo$/*\n*/", "foo$/*\n*/",
"foo$/*comment*/ \n", "foo$/*comment*/ \n",
"foo$/*\n*/ ", "foo$/*\n*/ ",
"foo $// comment\n", "foo $// comment\n",
"foo $// comment",
"foo $/*comment*/\n", "foo $/*comment*/\n",
"foo $/*\n*/", "foo $/*\n*/",
"foo $/* */ /* \n */ bar$/**/\n", "foo $/* */ /* \n */ bar$/**/\n",
...@@ -410,7 +412,8 @@ var lines = []string{ ...@@ -410,7 +412,8 @@ var lines = []string{
"foo $/*0*/ /*1*/ /*2*/ \n", "foo $/*0*/ /*1*/ /*2*/ \n",
"foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa$\n", "foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa$\n",
"foo $/* an EOF terminates a line */", "foo $/* an EOF terminates a line */",
"foo $/* an EOF terminates a line *//*", "foo $/* an EOF terminates a line */ /*",
"foo $/* an EOF terminates a line */ //",
"package main$\n\nfunc main() {\n\tif {\n\t\treturn /* */ }$\n}$\n", "package main$\n\nfunc main() {\n\tif {\n\t\treturn /* */ }$\n}$\n",
"package main$", "package main$",
...@@ -626,8 +629,6 @@ var errors = []struct { ...@@ -626,8 +629,6 @@ var errors = []struct {
{"`", token.STRING, 0, "string not terminated"}, {"`", token.STRING, 0, "string not terminated"},
{"/**/", token.COMMENT, 0, ""}, {"/**/", token.COMMENT, 0, ""},
{"/*", token.COMMENT, 0, "comment not terminated"}, {"/*", token.COMMENT, 0, "comment not terminated"},
{"//\n", token.COMMENT, 0, ""},
{"//", token.COMMENT, 0, "comment not terminated"},
{"077", token.INT, 0, ""}, {"077", token.INT, 0, ""},
{"078.", token.FLOAT, 0, ""}, {"078.", token.FLOAT, 0, ""},
{"07801234567.", token.FLOAT, 0, ""}, {"07801234567.", token.FLOAT, 0, ""},
......
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