1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:14:40 -07:00

cmd/yacc: allow leading underscore in token name

Fixes #4037.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6488093
This commit is contained in:
Rob Pike 2012-09-07 09:31:51 -07:00
parent 0cab7d52d5
commit cbc9ab75cb
2 changed files with 8 additions and 8 deletions

View File

@ -78,7 +78,7 @@ var vflag bool
%token <vval> VAL
%token <vvar> VAR
%token <numb> SUP
%token <numb> _SUP // tests leading underscore in token name
%%
prog:
':' VAR expr
@ -159,7 +159,7 @@ expr3:
expr2:
expr1
| expr2 SUP
| expr2 _SUP
{
xpn(&$$, &$1, $2)
}
@ -236,13 +236,13 @@ loop:
return '/'
case '¹', 'ⁱ':
yylval.numb = 1
return SUP
return _SUP
case '²', '⁲':
yylval.numb = 2
return SUP
return _SUP
case '³', '⁳':
yylval.numb = 3
return SUP
return _SUP
}
return int(c)

View File

@ -988,7 +988,7 @@ func gettok() int {
func getword(c rune) {
tokname = ""
for isword(c) || isdigit(c) || c == '_' || c == '.' || c == '$' {
for isword(c) || isdigit(c) || c == '.' || c == '$' {
tokname += string(c)
c = getrune(finput)
}
@ -1338,7 +1338,7 @@ loop:
if j >= max {
errorf("Illegal use of $%v", j)
}
} else if isword(c) || c == '_' || c == '.' {
} else if isword(c) || c == '.' {
// look for $name
ungetrune(finput, c)
if gettok() != IDENTIFIER {
@ -3090,7 +3090,7 @@ var peekrune rune
func isdigit(c rune) bool { return c >= '0' && c <= '9' }
func isword(c rune) bool {
return c >= 0xa0 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
return c >= 0xa0 || c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
}
func mktemp(t string) string { return t }