1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:44:39 -07:00

goyacc: fix handling of / and comments in goyacc

Fixes #618.

R=rsc
CC=golang-dev
https://golang.org/cl/217094
This commit is contained in:
Rob Pike 2010-02-23 16:00:14 +11:00
parent 8ba5c5593f
commit 38202de114

View File

@ -1352,13 +1352,31 @@ loop:
return return
case '/': case '/':
nc := getrune(finput)
if nc != '/' && nc != '*' {
ungetrune(finput, nc)
break
}
// a comment // a comment
putrune(ftable, c) putrune(ftable, c)
putrune(ftable, nc)
c = getrune(finput) c = getrune(finput)
for c != EOF { for c != EOF {
if c == '\n' { switch {
case c == '\n':
lineno++ lineno++
break swt if nc == '/' { // end of // comment
break swt
}
case c == '*' && nc == '*': // end of /* comment?
nnc := getrune(finput)
if nnc == '/' {
putrune(ftable, '*')
putrune(ftable, '/')
c = getrune(finput)
break swt
}
ungetrune(finput, nnc)
} }
putrune(ftable, c) putrune(ftable, c)
c = getrune(finput) c = getrune(finput)