]> Cypherpunks repositories - gostls13.git/commit
cmd/yacc: fix parsing of character tokens
authorRuss Cox <rsc@golang.org>
Fri, 26 Sep 2014 21:03:31 +0000 (17:03 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 26 Sep 2014 21:03:31 +0000 (17:03 -0400)
commitbfebf9ea8071683af608b8bf291fc7d8365d501b
tree1246475f3e231cf55c5d0f0e9a7978e8646c64be
parentb2487ef6a399790cfe57127c3f50fc59341460e4
cmd/yacc: fix parsing of character tokens

From issue 7967 I learned:

1) yacc accepts either 'x' or "x" to mean token value 0x78
2) yacc also accepts 'xyz' and "XYZ" to mean token value 0x78

Use strconv.Unquote to simplify the handling of quoted
strings and check that each has only one rune.

Although this does clean things up, it makes 'x' and "x"
treated as different internally (now they are stored as
`'x'` and `"x"`; before they were both ` x`). Grammars that
use both interchangeably will now die with an error
similar to the one from issue 7967:

        yacc bug -- cannot have 2 different Ts with same value
                "+" and '+'

The echoing of the quotes should make clear what is going on.

The other semantic change caused by using strconv.Unquote
is that '\"' and "\'" are no longer valid. Like in Go, they must be
spelled without the backslash: '"' and "'".

On the other hand, now yacc and Go agree about what character
and string literals mean.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/149110043
src/cmd/yacc/yacc.go