Skip to content

Commit 956d8df

Browse files
committed
Avoid needing a ParserConfiguration in YARPTranslatorDriver
1 parent 19f1894 commit 956d8df

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/main/java/org/truffleruby/parser/YARPTranslatorDriver.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import org.truffleruby.language.locals.WriteLocalVariableNode;
8484
import org.truffleruby.language.methods.Arity;
8585
import org.truffleruby.language.methods.SharedMethodInfo;
86-
import org.truffleruby.parser.parser.ParserConfiguration;
8786
import org.truffleruby.shared.Metrics;
8887
import org.prism.Nodes;
8988
import org.prism.ParseResult;
@@ -159,19 +158,6 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
159158
// TODO: add these variables and treat it more like an eval case
160159
}
161160

162-
String sourcePath = rubySource.getSourcePath(language);
163-
boolean isInlineSource = sourcePath.equals("-e");
164-
boolean isEvalParse = parserContext.isEval();
165-
final ParserConfiguration parserConfiguration = new ParserConfiguration(
166-
context,
167-
isInlineSource,
168-
!isEvalParse,
169-
false);
170-
171-
if (language.options.FROZEN_STRING_LITERALS) {
172-
parserConfiguration.setFrozenStringLiteral(true);
173-
}
174-
175161
// Parse to the YARP AST
176162
final RubyDeferredWarnings rubyWarnings = new RubyDeferredWarnings();
177163

@@ -192,13 +178,10 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
192178
printParseTranslateExecuteMetric("after-parsing", context, source);
193179
}
194180

195-
handleWarningsErrorsPrimitives(context, language, parseResult, rubySource, parserConfiguration, rubyWarnings);
181+
handleWarningsErrorsPrimitives(context, language, parseResult, rubySource, parseEnvironment, rubyWarnings);
196182

197183
var node = parseResult.value;
198184

199-
// Needs the magic comment to be parsed
200-
parseEnvironment.allowTruffleRubyPrimitives = parserConfiguration.allowTruffleRubyPrimitives;
201-
202185
final SourceSection sourceSection = source.createSection(0, rubySource.getBytes().length);
203186
final SourceIndexLength sourceIndexLength = SourceIndexLength.fromSourceSection(sourceSection);
204187

@@ -431,7 +414,7 @@ public static ParseResult parseToYARPAST(RubyLanguage language, RubySource rubyS
431414
}
432415

433416
public static void handleWarningsErrorsPrimitives(RubyContext context, RubyLanguage language,
434-
ParseResult parseResult, RubySource rubySource, ParserConfiguration configuration,
417+
ParseResult parseResult, RubySource rubySource, ParseEnvironment parseEnvironment,
435418
RubyDeferredWarnings rubyWarnings) {
436419

437420
// intern() to improve footprint
@@ -473,6 +456,7 @@ public static void handleWarningsErrorsPrimitives(RubyContext context, RubyLangu
473456
context.getCoreExceptions().syntaxErrorAlreadyWithFileLine(message, null, section));
474457
}
475458

459+
boolean allowTruffleRubyPrimitives = false;
476460
for (var magicComment : parseResult.magicComments) {
477461
String name = rubySource.getTStringWithEncoding()
478462
.substring(magicComment.keyLocation.startOffset, magicComment.keyLocation.length).toJavaString();
@@ -483,9 +467,10 @@ public static void handleWarningsErrorsPrimitives(RubyContext context, RubyLangu
483467

484468
// check the `primitive` TruffleRuby specific magic comment
485469
if (MagicCommentParser.isMagicTruffleRubyPrimitivesComment(name)) {
486-
configuration.allowTruffleRubyPrimitives = value.equalsIgnoreCase("true");
470+
allowTruffleRubyPrimitives = value.equalsIgnoreCase("true");
487471
}
488472
}
473+
parseEnvironment.allowTruffleRubyPrimitives = allowTruffleRubyPrimitives;
489474
}
490475

491476
public static void handleWarningsErrorsNoContext(RubyLanguage language, ParseResult parseResult,

0 commit comments

Comments
 (0)