3333
3434import org .antlr .v4 .runtime .CharStreams ;
3535import org .antlr .v4 .runtime .CodePointCharStream ;
36- import org .antlr .v4 .runtime .NoViableAltException ;
3736import org .antlr .v4 .runtime .ParserRuleContext ;
38- import org .antlr .v4 .runtime .RecognitionException ;
39- import org .antlr .v4 .runtime .Token ;
4037
4138import com .oracle .graal .python .PythonLanguage ;
4239import com .oracle .graal .python .nodes .PNode ;
@@ -95,20 +92,12 @@ private static ParserRuleContext preParseWithAntlr(PythonCore core, Source sourc
9592 parser .reset ();
9693 input = parser .eval_input ();
9794 } catch (Throwable e2 ) {
98- int line ;
9995 if (source .isInteractive () && e instanceof PIncompleteSourceException ) {
10096 ((PIncompleteSourceException ) e ).setSource (source );
10197 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 ());
11098 }
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 ());
112101 }
113102 }
114103 }
@@ -126,17 +115,8 @@ private static ParserRuleContext preParseInlineWithAntlr(PythonCore core, Source
126115 parser .reset ();
127116 input = parser .eval_input ();
128117 } 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 ());
140120 }
141121 }
142122 return input ;
0 commit comments