Commit 38202de1 authored by Rob Pike's avatar Rob Pike

goyacc: fix handling of / and comments in goyacc

Fixes #618.

R=rsc
CC=golang-dev
https://golang.org/cl/217094
parent 8ba5c559
...@@ -1352,13 +1352,31 @@ loop: ...@@ -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)
......
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