25
25
*/
26
26
package com .oracle .graal .python .parser ;
27
27
28
+ import java .io .ByteArrayInputStream ;
29
+ import java .io .ByteArrayOutputStream ;
30
+ import java .io .DataInputStream ;
31
+ import java .io .DataOutputStream ;
32
+ import java .io .IOException ;
33
+
34
+ import org .antlr .v4 .runtime .CharStreams ;
35
+ import org .antlr .v4 .runtime .CommonTokenStream ;
36
+ import org .antlr .v4 .runtime .Token ;
37
+ import org .graalvm .nativeimage .ImageInfo ;
38
+
39
+ import com .oracle .graal .python .PythonFileDetector ;
28
40
import com .oracle .graal .python .PythonLanguage ;
29
41
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
30
42
import com .oracle .graal .python .nodes .ModuleRootNode ;
31
43
import com .oracle .graal .python .nodes .function .FunctionDefinitionNode ;
32
44
import com .oracle .graal .python .nodes .function .GeneratorFunctionDefinitionNode ;
33
45
import com .oracle .graal .python .nodes .util .BadOPCodeNode ;
34
- import org .antlr .v4 .runtime .CharStreams ;
35
- import org .antlr .v4 .runtime .CommonTokenStream ;
36
-
37
- import com .oracle .graal .python .PythonFileDetector ;
38
46
import com .oracle .graal .python .parser .antlr .DescriptiveBailErrorListener ;
39
47
import com .oracle .graal .python .parser .antlr .Python3Lexer ;
40
48
import com .oracle .graal .python .parser .antlr .Python3Parser ;
59
67
import com .oracle .truffle .api .nodes .RootNode ;
60
68
import com .oracle .truffle .api .source .Source ;
61
69
import com .oracle .truffle .api .source .SourceSection ;
62
- import java .io .ByteArrayInputStream ;
63
- import java .io .ByteArrayOutputStream ;
64
- import java .io .DataInputStream ;
65
- import java .io .DataOutputStream ;
66
- import java .io .IOException ;
67
- import org .antlr .v4 .runtime .Token ;
68
- import org .graalvm .nativeimage .ImageInfo ;
69
70
70
71
public final class PythonParserImpl implements PythonParser , PythonCodeSerializer {
71
72
@@ -82,15 +83,8 @@ public PythonParserImpl(Env env) {
82
83
this .timeStatistics = env .getOptions ().get (PythonOptions .ParserStatistics );
83
84
}
84
85
85
- private static Python3Parser getPython3Parser (Source source , ParserErrorCallback errors ) {
86
- Python3Lexer lexer ;
87
- try {
88
- lexer = source .getPath () == null
89
- ? new Python3Lexer (CharStreams .fromString (source .getCharacters ().toString ()))
90
- : new Python3Lexer (CharStreams .fromFileName (source .getPath ()));
91
- } catch (IOException ex ) {
92
- lexer = new Python3Lexer (CharStreams .fromString (source .getCharacters ().toString ()));
93
- }
86
+ private static Python3Parser getPython3Parser (Source source , String sourceText , ParserErrorCallback errors ) {
87
+ Python3Lexer lexer = new Python3Lexer (CharStreams .fromString (sourceText ));
94
88
lexer .removeErrorListeners ();
95
89
lexer .addErrorListener (ERROR_LISTENER );
96
90
Python3Parser parser = new Python3Parser (new CommonTokenStream (lexer ));
@@ -281,7 +275,7 @@ private CacheItem parseWithANTLR(ParserMode mode, ParserErrorCallback errors, Py
281
275
}
282
276
}
283
277
// ANTLR parsing
284
- Python3Parser parser = getPython3Parser (source , errors );
278
+ Python3Parser parser = getPython3Parser (source , sourceText , errors );
285
279
parser .setFactory (sstFactory );
286
280
SSTNode parserSSTResult = null ;
287
281
0 commit comments