]> Cypherpunks repositories - gostls13.git/commitdiff
goyacc: fix handling of / and comments in goyacc
authorRob Pike <r@golang.org>
Tue, 23 Feb 2010 05:00:14 +0000 (16:00 +1100)
committerRob Pike <r@golang.org>
Tue, 23 Feb 2010 05:00:14 +0000 (16:00 +1100)
Fixes #618.

R=rsc
CC=golang-dev
https://golang.org/cl/217094

src/cmd/goyacc/goyacc.go

index 4e4819b40b92a6df40d18a56bcbcb1d0f0c072f8..4d9a515a6062bb9052e08ddc1b3e2cfa33bd22c9 100644 (file)
@@ -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)