FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
cmd/yacc: allow leading underscore in token name
Fixes issue 4037.

Please review this at http://codereview.appspot.com/6488093/

Affected files:
M src/cmd/yacc/units.y
M src/cmd/yacc/yacc.go


Index: src/cmd/yacc/units.y
===================================================================
--- a/src/cmd/yacc/units.y
+++ b/src/cmd/yacc/units.y
@@ -78,7 +78,7 @@

%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 @@

expr2:
expr1
-| expr2 SUP
+| expr2 _SUP
{
xpn(&$$, &$1, $2)
}
@@ -236,13 +236,13 @@
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)

Index: src/cmd/yacc/yacc.go
===================================================================
--- a/src/cmd/yacc/yacc.go
+++ b/src/cmd/yacc/yacc.go
@@ -988,7 +988,7 @@

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 @@
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 @@
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 }

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 7, '12 at 4:04p
activeSep 7, '12 at 4:31p
posts3
users2
websitegolang.org

2 users in discussion

R: 2 posts Russ Cox: 1 post

People

Translate

site design / logo © 2022 Grokbase