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