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 ;
36
37
import org .antlr .v4 .runtime .ParserRuleContext ;
38
+ import org .antlr .v4 .runtime .RecognitionException ;
39
+ import org .antlr .v4 .runtime .Token ;
37
40
38
41
import com .oracle .graal .python .PythonLanguage ;
39
42
import com .oracle .graal .python .nodes .PNode ;
@@ -92,11 +95,20 @@ private static ParserRuleContext preParseWithAntlr(PythonCore core, Source sourc
92
95
parser .reset ();
93
96
input = parser .eval_input ();
94
97
} catch (Throwable e2 ) {
98
+ int line ;
95
99
if (source .isInteractive () && e instanceof PIncompleteSourceException ) {
96
100
((PIncompleteSourceException ) e ).setSource (source );
97
101
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 ());
98
110
}
99
- throw core .raise (SyntaxError , e .getMessage ());
111
+ throw core .raise (SyntaxError , getLocation ( source , line ), e .getMessage ());
100
112
}
101
113
}
102
114
}
@@ -114,7 +126,17 @@ private static ParserRuleContext preParseInlineWithAntlr(PythonCore core, Source
114
126
parser .reset ();
115
127
input = parser .eval_input ();
116
128
} catch (Throwable e2 ) {
117
- throw core .raise (SyntaxError , e .getMessage ());
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
140
}
119
141
}
120
142
return input ;
0 commit comments