33
33
34
34
import org .antlr .v4 .runtime .CharStreams ;
35
35
import org .antlr .v4 .runtime .CodePointCharStream ;
36
- import org .antlr .v4 .runtime .NoViableAltException ;
37
36
import org .antlr .v4 .runtime .ParserRuleContext ;
38
- import org .antlr .v4 .runtime .RecognitionException ;
39
- import org .antlr .v4 .runtime .Token ;
40
37
41
38
import com .oracle .graal .python .PythonLanguage ;
42
39
import com .oracle .graal .python .nodes .PNode ;
@@ -95,20 +92,12 @@ private static ParserRuleContext preParseWithAntlr(PythonCore core, Source sourc
95
92
parser .reset ();
96
93
input = parser .eval_input ();
97
94
} catch (Throwable e2 ) {
98
- int line ;
99
95
if (source .isInteractive () && e instanceof PIncompleteSourceException ) {
100
96
((PIncompleteSourceException ) e ).setSource (source );
101
97
throw e ;
102
- } else if (e instanceof RecognitionException ) {
103
- Token token = ((RecognitionException ) e ).getOffendingToken ();
104
- line = token .getLine ();
105
- } else if (e .getCause () instanceof NoViableAltException ) {
106
- Token token = ((NoViableAltException ) e .getCause ()).getOffendingToken ();
107
- line = token .getLine ();
108
- } else {
109
- throw core .raise (SyntaxError , e .getMessage ());
110
98
}
111
- throw core .raise (SyntaxError , getLocation (source , line ), e .getMessage ());
99
+ Node location = getLocation (source , PythonErrorStrategy .getLine (e ));
100
+ throw core .raise (SyntaxError , location , e .getMessage ());
112
101
}
113
102
}
114
103
}
@@ -126,17 +115,8 @@ private static ParserRuleContext preParseInlineWithAntlr(PythonCore core, Source
126
115
parser .reset ();
127
116
input = parser .eval_input ();
128
117
} catch (Throwable e2 ) {
129
- int line ;
130
- if (e instanceof RecognitionException ) {
131
- Token token = ((RecognitionException ) e ).getOffendingToken ();
132
- line = token .getLine ();
133
- } else if (e .getCause () instanceof NoViableAltException ) {
134
- Token token = ((NoViableAltException ) e .getCause ()).getOffendingToken ();
135
- line = token .getLine ();
136
- } else {
137
- throw core .raise (SyntaxError , e .getMessage ());
138
- }
139
- throw core .raise (SyntaxError , getLocation (source , line ), e .getMessage ());
118
+ Node location = getLocation (source , PythonErrorStrategy .getLine (e ));
119
+ throw core .raise (SyntaxError , location , e .getMessage ());
140
120
}
141
121
}
142
122
return input ;
0 commit comments