]> Cypherpunks repositories - gostls13.git/commitdiff
Add Error member to yyLexer type (yyError
authorRoger Peppe <rogpeppe@gmail.com>
Mon, 17 May 2010 19:23:48 +0000 (12:23 -0700)
committerKen Thompson <ken@golang.org>
Mon, 17 May 2010 19:23:48 +0000 (12:23 -0700)
has no access to yylex)

R=ken2, ken3
CC=golang-dev
https://golang.org/cl/813047

src/cmd/goyacc/doc.go
src/cmd/goyacc/goyacc.go
src/cmd/goyacc/units.y

index eea70adabbbf28d7a0f9fb6671d3e98ff17763e2..686f75745250dacf23dd80b976b94f54ba12e636 100644 (file)
@@ -24,10 +24,12 @@ argument that conforms to the following interface:
 
        type yyLexer interface {
                Lex(lval *yySymType) int
+               Error(e string)
        }
 
 Lex should return the token identifier, and place other token
 information in lval (which replaces the usual yylval).
+Error is equivalent to yyerror in the original yacc.
 
 Code inside the parser may refer to the variable yylex
 which holds the yyLexer passed to Parse.
index 118d277f6b80e2e25428ee7c113b90066fc76c84..a5da5f0a1d54cd97b082a4cba1850581b9c3e6e4 100644 (file)
@@ -3080,6 +3080,7 @@ var yyDebug = 0
 
 type yyLexer interface {
        Lex(lval *yySymType) int
+       Error(s string)
 }
 
 const yyFlag = -1000
@@ -3162,7 +3163,7 @@ ret1:
 yystack:
        /* put a state and value onto the stack */
        if yyDebug >= 4 {
-               fmt.Printf("char %v in %v", yyTokname(yychar), yyStatname(yystate))
+               fmt.Printf("char %v in %v\n", yyTokname(yychar), yyStatname(yystate))
        }
 
        yyp++
@@ -3228,7 +3229,7 @@ yydefault:
                /* error ... attempt to resume parsing */
                switch Errflag {
                case 0: /* brand new error */
-                       yyError("syntax error")
+                       yylex.Error("syntax error")
                        Nerrs++
                        if yyDebug >= 1 {
                                fmt.Printf("%s", yyStatname(yystate))
@@ -3273,7 +3274,7 @@ yydefault:
 
        /* reduction by production yyn */
        if yyDebug >= 2 {
-               fmt.Printf("reduce %v in:\n\t%v", yyn, yyStatname(yystate))
+               fmt.Printf("reduce %v in:\n\t%v\n", yyn, yyStatname(yystate))
        }
 
        yynt := yyn
index b909d115c6b567b2d1a8d935d094eebe254b7628..bd5517e8be3ea57be2458b9ad4255405370762e1 100644 (file)
@@ -215,7 +215,7 @@ expr0:
 
 type UnitsLex int
 
-func (l UnitsLex) Lex(yylval *yySymType) int {
+func (_ UnitsLex) Lex(yylval *yySymType) int {
        var c, i int
 
        c = peekrune
@@ -280,6 +280,10 @@ numb:
        return VAL
 }
 
+func (_ UnitsLex) Error(s string) {
+       Error("syntax error, last name: %v", sym)
+}
+
 func main() {
        var file string
 
@@ -384,10 +388,6 @@ func rdigit(c int) bool {
        return false
 }
 
-func yyError(s string) {
-       Error("syntax error, last name: %v", sym)
-}
-
 func Error(s string, v ...interface{}) {
        fmt.Printf("%v: %v\n\t", lineno, line)
        fmt.Printf(s, v)