cmd/goyacc: fix an off-by-one error in lineno tracking
Previously, goyacc's line number tracking would run off by one whenever
a multiline comment was used inside of an action, like so:
expr:
TOKEN
{
/* Hello. */
}
This is because the character after the multi-line comment close marker
(i.e., the character immediately after `*/`) was blindly printed out
instead of properly accounted for. A newline character after a
multi-line comment would fail to increment lineno, for example, and any
error messages generated after that point would refer to the wrong line.
Similarly, a variable reference after a multi-line comment, like
$$.val = &someStruct{Value: /* oops */$1}
would copy the $ literally into the resulting Go code. (This was not a
problem in practice because multi-line comments are typically followed
by whitespace.)
Adjust the control flow so the character after the multi-line comment
close marker character gets run through the relevant switch statement
and accounted for.
Change-Id: I276b6ffdb7626101f76811b7ee4804bacc6ef740
Reviewed-on: https://go-review.googlesource.com/110495
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/cmd/goyacc/yacc.go b/cmd/goyacc/yacc.go
index 062bc47..d831f67 100644
--- a/cmd/goyacc/yacc.go
+++ b/cmd/goyacc/yacc.go
@@ -1412,8 +1412,7 @@
if nnc == '/' {
fcode.WriteRune('*')
fcode.WriteRune('/')
- c = getrune(finput)
- break swt
+ continue loop
}
ungetrune(finput, nnc)
}