@@ -90,7 +90,7 @@ func (x *yyLex) refill() {
90
90
x .eof = true
91
91
default :
92
92
x .eof = true
93
- x .Errorf ("Error reading input: %v" , err )
93
+ x .SyntaxErrorf ("Error reading input: %v" , err )
94
94
}
95
95
// If this is exec input, add a newline to the end of the
96
96
// string if there isn't one already.
@@ -129,7 +129,7 @@ func countIndent(s string) int {
129
129
// a b
130
130
indent += tabSize - (indent & (tabSize - 1 ))
131
131
default :
132
- panic ("bad indent" )
132
+ panic (py . ExceptionNewf ( py . IndentationError , "unexpected indent") )
133
133
}
134
134
135
135
}
@@ -399,7 +399,7 @@ func (x *yyLex) Lex(yylval *yySymType) (ret int) {
399
399
goto foundIndent
400
400
}
401
401
}
402
- x .Error ("Inconsistent indent" )
402
+ x .SyntaxError ("Inconsistent indent" )
403
403
return eof
404
404
foundIndent:
405
405
x .indentStack = x .indentStack [:len (x .indentStack )- 1 ]
@@ -489,7 +489,7 @@ func (x *yyLex) Lex(yylval *yySymType) (ret int) {
489
489
}
490
490
491
491
// Nothing we recognise found
492
- x .Error ("invalid syntax" )
492
+ x .SyntaxError ("invalid syntax" )
493
493
return eof
494
494
case checkEof :
495
495
if x .eof {
@@ -683,8 +683,9 @@ isNumber:
683
683
value = py .Complex (complex (0 , f ))
684
684
} else {
685
685
// Discard numbers with leading 0 except all 0s
686
- if illegalDecimalInteger .FindString (x .line ) != "" {
687
- x .Error ("illegal decimal with leading zero" )
686
+ if illegalDecimalInteger .FindString (s ) != "" {
687
+ // FIXME where is this error going in the grammar?
688
+ x .SyntaxError ("illegal decimal with leading zero" )
688
689
return eofError , nil
689
690
}
690
691
value , err = py .IntFromString (s , 10 )
@@ -806,12 +807,12 @@ found:
806
807
}
807
808
}
808
809
if ! multiLineString {
809
- x .Errorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
810
+ x .SyntaxErrorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
810
811
return eofError , nil
811
812
}
812
813
readMore:
813
814
if x .eof {
814
- x .Errorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
815
+ x .SyntaxErrorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
815
816
return eofError , nil
816
817
}
817
818
x .refill ()
@@ -821,7 +822,7 @@ foundEndOfString:
821
822
var err error
822
823
buf , err = DecodeEscape (buf , byteString )
823
824
if err != nil {
824
- x .Errorf ("Decode error: %v" , err )
825
+ x .SyntaxErrorf ("Decode error: %v" , err )
825
826
return eofError , nil
826
827
}
827
828
}
@@ -834,23 +835,31 @@ foundEndOfString:
834
835
// The parser calls this method on a parse error.
835
836
func (x * yyLex ) Error (s string ) {
836
837
x .error = true
837
- x .errorString = s
838
838
if yyDebug >= 1 {
839
839
log .Printf ("Parse error: %s" , s )
840
840
log .Printf ("Parse buffer %q" , x .line )
841
841
log .Printf ("State %#v" , x )
842
842
}
843
843
}
844
844
845
+ // The parser calls this method on a parse error.
846
+ func (x * yyLex ) SyntaxError (s string ) {
847
+ x .errorString = s
848
+ x .Error (s )
849
+ }
850
+
845
851
// Call this to write formatted errors
846
- func (x * yyLex ) Errorf (format string , a ... interface {}) {
847
- x .Error (fmt .Sprintf (format , a ... ))
852
+ func (x * yyLex ) SyntaxErrorf (format string , a ... interface {}) {
853
+ x .SyntaxError (fmt .Sprintf (format , a ... ))
848
854
}
849
855
850
856
// Returns an python error for the current yyLex
851
857
func (x * yyLex ) ErrorReturn () error {
852
858
if x .error {
853
- return py .ExceptionNewf (py .SyntaxError , "Syntax Error: %s" , x .errorString )
859
+ if x .errorString == "" {
860
+ x .errorString = "invalid syntax"
861
+ }
862
+ return py .ExceptionNewf (py .SyntaxError , "%s" , x .errorString )
854
863
}
855
864
return nil
856
865
}
0 commit comments