1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:24:41 -07:00
go/cmd/goyacc
Nikhil Benesch 836e0f611e 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>
2018-05-01 01:19:15 +00:00
..
testdata/expr cmd/goyacc: move go tool yacc from the go repo 2016-08-18 15:37:45 +00:00
doc.go cmd/goyacc: move go tool yacc from the go repo 2016-08-18 15:37:45 +00:00
yacc.go cmd/goyacc: fix an off-by-one error in lineno tracking 2018-05-01 01:19:15 +00:00