summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-02-23 16:00:14 +1100
committerRob Pike <r@golang.org>2010-02-23 16:00:14 +1100
commit692ad38441b38651928daf101e85d932c0c3c72a (patch)
treeb48fdb17270728dc2da66d7ff973d485c11f9772 /src
parent5ebae25d67e5af7a8494fc34c31695dc0747611f (diff)
downloadgolang-692ad38441b38651928daf101e85d932c0c3c72a.tar.gz
goyacc: fix handling of / and comments in goyacc
Fixes issue 618. R=rsc CC=golang-dev http://codereview.appspot.com/217094
Diffstat (limited to 'src')
-rw-r--r--src/cmd/goyacc/goyacc.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/cmd/goyacc/goyacc.go b/src/cmd/goyacc/goyacc.go
index 4e4819b40..4d9a515a6 100644
--- a/src/cmd/goyacc/goyacc.go
+++ b/src/cmd/goyacc/goyacc.go
@@ -1352,13 +1352,31 @@ loop:
return
case '/':
+ nc := getrune(finput)
+ if nc != '/' && nc != '*' {
+ ungetrune(finput, nc)
+ break
+ }
// a comment
putrune(ftable, c)
+ putrune(ftable, nc)
c = getrune(finput)
for c != EOF {
- if c == '\n' {
+ switch {
+ case c == '\n':
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)
c = getrune(finput)