mirror of
https://github.com/golang/go
synced 2024-11-05 11:46:12 -07:00
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>
This commit is contained in:
parent
165bdd618e
commit
836e0f611e
@ -1412,8 +1412,7 @@ loop:
|
||||
if nnc == '/' {
|
||||
fcode.WriteRune('*')
|
||||
fcode.WriteRune('/')
|
||||
c = getrune(finput)
|
||||
break swt
|
||||
continue loop
|
||||
}
|
||||
ungetrune(finput, nnc)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user