mirror of
https://github.com/golang/go
synced 2024-11-21 21:54:40 -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:
parent
132e5435e3
commit
3a50d721a8
@ -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",
|
||||
@ -411,6 +413,7 @@ var lines = []string{
|
||||
"foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa$\n",
|
||||
"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, ""},
|
||||
|
Loading…
Reference in New Issue
Block a user