1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:00:09 -07:00

go/scanner: line comments may end in EOF

R=rsc
CC=golang-dev
https://golang.org/cl/2908041
This commit is contained in:
Robert Griesemer 2010-11-04 13:15:42 -07:00
parent 132e5435e3
commit 3a50d721a8
2 changed files with 21 additions and 24 deletions

View File

@ -183,29 +183,25 @@ func (S *Scanner) scanComment() {
if S.ch == '/' { if S.ch == '/' {
//-style comment //-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)
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() S.next()
for S.ch >= 0 { for S.ch != '\n' && S.ch >= 0 {
ch := S.ch
S.next() S.next()
if ch == '*' && S.ch == '/' { }
S.next() if col == 1 {
return // comment starts at the beginning of the current line
} S.interpretLineComment(S.src[offs:S.offset])
}
return
}
/*-style comment */
S.next()
for S.ch >= 0 {
ch := S.ch
S.next()
if ch == '*' && S.ch == '/' {
S.next()
return
} }
} }

View File

@ -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{
"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 {
{"`", 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, ""},