@@ -90,7 +90,7 @@ func (x *yyLex) refill() {
9090 x .eof = true
9191 default :
9292 x .eof = true
93- x .Errorf ("Error reading input: %v" , err )
93+ x .SyntaxErrorf ("Error reading input: %v" , err )
9494 }
9595 // If this is exec input, add a newline to the end of the
9696 // string if there isn't one already.
@@ -129,7 +129,7 @@ func countIndent(s string) int {
129129 // a b
130130 indent += tabSize - (indent & (tabSize - 1 ))
131131 default :
132- panic ("bad indent" )
132+ panic (py . ExceptionNewf ( py . IndentationError , "unexpected indent") )
133133 }
134134
135135 }
@@ -399,7 +399,7 @@ func (x *yyLex) Lex(yylval *yySymType) (ret int) {
399399 goto foundIndent
400400 }
401401 }
402- x .Error ("Inconsistent indent" )
402+ x .SyntaxError ("Inconsistent indent" )
403403 return eof
404404 foundIndent:
405405 x .indentStack = x .indentStack [:len (x .indentStack )- 1 ]
@@ -489,7 +489,7 @@ func (x *yyLex) Lex(yylval *yySymType) (ret int) {
489489 }
490490
491491 // Nothing we recognise found
492- x .Error ("invalid syntax" )
492+ x .SyntaxError ("invalid syntax" )
493493 return eof
494494 case checkEof :
495495 if x .eof {
@@ -683,8 +683,9 @@ isNumber:
683683 value = py .Complex (complex (0 , f ))
684684 } else {
685685 // 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" )
688689 return eofError , nil
689690 }
690691 value , err = py .IntFromString (s , 10 )
@@ -806,12 +807,12 @@ found:
806807 }
807808 }
808809 if ! multiLineString {
809- x .Errorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
810+ x .SyntaxErrorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
810811 return eofError , nil
811812 }
812813 readMore:
813814 if x .eof {
814- x .Errorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
815+ x .SyntaxErrorf ("Unterminated %sx%s string" , stringEnd , stringEnd )
815816 return eofError , nil
816817 }
817818 x .refill ()
@@ -821,7 +822,7 @@ foundEndOfString:
821822 var err error
822823 buf , err = DecodeEscape (buf , byteString )
823824 if err != nil {
824- x .Errorf ("Decode error: %v" , err )
825+ x .SyntaxErrorf ("Decode error: %v" , err )
825826 return eofError , nil
826827 }
827828 }
@@ -834,23 +835,31 @@ foundEndOfString:
834835// The parser calls this method on a parse error.
835836func (x * yyLex ) Error (s string ) {
836837 x .error = true
837- x .errorString = s
838838 if yyDebug >= 1 {
839839 log .Printf ("Parse error: %s" , s )
840840 log .Printf ("Parse buffer %q" , x .line )
841841 log .Printf ("State %#v" , x )
842842 }
843843}
844844
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+
845851// 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 ... ))
848854}
849855
850856// Returns an python error for the current yyLex
851857func (x * yyLex ) ErrorReturn () error {
852858 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 )
854863 }
855864 return nil
856865}
0 commit comments