@@ -68,26 +68,47 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
68
68
69
69
String entireMessage = e == null || e .getMessage () == null ? "invalid syntax" : e .getMessage ();
70
70
71
+ IntervalSet expectedTokens = null ;
72
+ if (e != null ) {
73
+ expectedTokens = e .getExpectedTokens ();
74
+ } else if (recognizer instanceof Python3Parser ) {
75
+ expectedTokens = ((Python3Parser ) recognizer ).getExpectedTokens ();
76
+ }
77
+
71
78
if (isInteractive (recognizer )) {
72
- PIncompleteSourceException handleRecognitionException = null ;
73
- if (e != null ) {
74
- handleRecognitionException = handleRecognitionException (e .getExpectedTokens (), entireMessage , e , line );
75
- } else if (recognizer instanceof Python3Parser ) {
76
- handleRecognitionException = handleRecognitionException (((Python3Parser ) recognizer ).getExpectedTokens (), entireMessage , null , line );
79
+ PIncompleteSourceException incompleteSourceException = null ;
80
+ if (expectedTokens != null ) {
81
+ incompleteSourceException = handleRecognitionException (expectedTokens , entireMessage , e , line );
77
82
}
78
- if (handleRecognitionException == null ) {
79
- handleRecognitionException = handleInteractiveException (recognizer , offendingSymbol );
83
+ if (incompleteSourceException == null ) {
84
+ incompleteSourceException = handleInteractiveException (recognizer , offendingSymbol );
80
85
}
81
- if (handleRecognitionException != null ) {
82
- throw handleRecognitionException ;
86
+ if (incompleteSourceException != null ) {
87
+ throw incompleteSourceException ;
83
88
}
84
89
}
90
+
85
91
if (offendingSymbol instanceof Token ) {
86
92
Token token = (Token ) offendingSymbol ;
87
93
ErrorType errorType = ErrorType .Generic ;
88
- if (token .getType () == Python3Parser .INDENT_ERROR ) {
89
- entireMessage = "unindent does not match any outer indentation level" ;
90
- errorType = ErrorType .Indentation ;
94
+ switch (token .getType ()) {
95
+ case Python3Parser .INDENT_ERROR :
96
+ entireMessage = "unindent does not match any outer indentation level" ;
97
+ errorType = ErrorType .Indentation ;
98
+ break ;
99
+ case Python3Parser .INDENT :
100
+ entireMessage = "unexpected indent" ;
101
+ errorType = ErrorType .Indentation ;
102
+ break ;
103
+ case Python3Parser .DEDENT :
104
+ entireMessage = "unexpected unindent" ;
105
+ errorType = ErrorType .Indentation ;
106
+ break ;
107
+ default :
108
+ if (expectedTokens != null && expectedTokens .contains (Python3Parser .INDENT )) {
109
+ entireMessage = "expected an indented block" ;
110
+ errorType = ErrorType .Indentation ;
111
+ }
91
112
}
92
113
throw new EmptyRecognitionException (errorType , entireMessage , recognizer , token );
93
114
}
0 commit comments