|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. |
3 | 3 | * Copyright (c) 2013, Regents of the University of California
|
4 | 4 | *
|
5 | 5 | * All rights reserved.
|
|
25 | 25 | */
|
26 | 26 | package com.oracle.graal.python.parser;
|
27 | 27 |
|
28 |
| -import com.oracle.graal.python.builtins.objects.PNone; |
29 |
| -import com.oracle.graal.python.builtins.objects.exception.PBaseException; |
30 | 28 | import org.antlr.v4.runtime.CharStreams;
|
31 | 29 | import org.antlr.v4.runtime.CommonTokenStream;
|
| 30 | +import org.antlr.v4.runtime.Token; |
32 | 31 |
|
33 | 32 | import com.oracle.graal.python.parser.antlr.DescriptiveBailErrorListener;
|
34 | 33 | import com.oracle.graal.python.parser.antlr.Python3Lexer;
|
|
40 | 39 | import com.oracle.graal.python.runtime.PythonParser;
|
41 | 40 | import com.oracle.graal.python.runtime.exception.PException;
|
42 | 41 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
43 |
| -import com.oracle.truffle.api.TruffleException; |
44 | 42 | import com.oracle.truffle.api.TruffleLanguage.Env;
|
45 | 43 | import com.oracle.truffle.api.frame.Frame;
|
46 | 44 | import com.oracle.truffle.api.frame.FrameDescriptor;
|
47 | 45 | import com.oracle.truffle.api.nodes.Node;
|
48 | 46 | import com.oracle.truffle.api.source.Source;
|
49 | 47 | import com.oracle.truffle.api.source.SourceSection;
|
50 |
| -import org.antlr.v4.runtime.Token; |
51 | 48 |
|
52 | 49 | public final class PythonParserImpl implements PythonParser {
|
53 | 50 |
|
@@ -152,18 +149,18 @@ public Node parseN(ParserMode mode, ParserErrorCallback errors, Source source, F
|
152 | 149 | parser.reset();
|
153 | 150 | parserSSTResult = parser.eval_input().result;
|
154 | 151 | } catch (Exception e2) {
|
155 |
| - throw handleParserError(errors, source, e, !(mode == ParserMode.InteractiveStatement || mode == ParserMode.Statement)); |
| 152 | + throw handleParserError(errors, source, e); |
156 | 153 | }
|
157 | 154 | } else {
|
158 |
| - throw handleParserError(errors, source, e, !(mode == ParserMode.InteractiveStatement || mode == ParserMode.Statement)); |
| 155 | + throw handleParserError(errors, source, e); |
159 | 156 | }
|
160 | 157 | }
|
161 | 158 |
|
162 | 159 | lastGlobalScope = sstFactory.getScopeEnvironment().getGlobalScope();
|
163 | 160 | try {
|
164 | 161 | return sstFactory.createParserResult(parserSSTResult, mode, currentFrame);
|
165 | 162 | } catch (Exception e) {
|
166 |
| - throw handleParserError(errors, source, e, !(mode == ParserMode.InteractiveStatement || mode == ParserMode.Statement)); |
| 163 | + throw handleParserError(errors, source, e); |
167 | 164 | }
|
168 | 165 | }
|
169 | 166 |
|
@@ -197,20 +194,11 @@ public String unescapeJavaString(String str) {
|
197 | 194 | return StringUtils.unescapeJavaString(str);
|
198 | 195 | }
|
199 | 196 |
|
200 |
| - private static PException handleParserError(ParserErrorCallback errors, Source source, Exception e, boolean showBadLine) { |
201 |
| - if (e instanceof TruffleException && ((TruffleException) e).isSyntaxError() && e instanceof PException) { |
202 |
| - if (!showBadLine) { |
203 |
| - PBaseException instance = ((PException) e).getExceptionObject(); |
204 |
| - // In cpython shell the line with the error is not displayed, so we should do it in |
205 |
| - // the same way. |
206 |
| - // This rely on implementation in traceback.py file. See comment in |
207 |
| - // Python3Core.raiseInvalidSyntax method |
208 |
| - instance.setAttribute("text", PNone.NONE); |
209 |
| - } |
210 |
| - return (PException) e; |
| 197 | + private static PException handleParserError(ParserErrorCallback errors, Source source, Exception e) { |
| 198 | + if (e instanceof PException && ((PException) e).isSyntaxError()) { |
| 199 | + throw (PException) e; |
211 | 200 | }
|
212 |
| - |
213 |
| - SourceSection section = showBadLine ? PythonErrorStrategy.getPosition(source, e) : source.createUnavailableSection(); |
| 201 | + SourceSection section = PythonErrorStrategy.getPosition(source, e); |
214 | 202 | // from parser we are getting RuntimeExceptions
|
215 | 203 | String message = e instanceof RuntimeException && e.getMessage() != null ? e.getMessage() : "invalid syntax";
|
216 | 204 | throw errors.raiseInvalidSyntax(source, section, message);
|
|
0 commit comments