Skip to content

Commit 953df20

Browse files
committed
Use Prism magic comments in YARPTranslatorDriver
1 parent 6277b08 commit 953df20

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
166166
parserConfiguration.setFrozenStringLiteral(true);
167167
}
168168

169-
RubyLexer.parseMagicComment(rubySource.getTStringWithEncoding(), (name, value) -> {
170-
if (RubyLexer.isMagicTruffleRubyPrimitivesComment(name)) {
171-
parserConfiguration.allowTruffleRubyPrimitives = value.equalsIgnoreCase("true");
172-
}
173-
});
174-
175169
// Parse to the YARP AST
176170

177171
final org.prism.Nodes.Node node;
@@ -456,6 +450,17 @@ public static org.prism.Nodes.Node parseToYARPAST(RubyContext context, RubyLangu
456450
}
457451
}
458452

453+
for (var magicComment : parseResult.magicComments) {
454+
String name = rubySource.getTStringWithEncoding()
455+
.substring(magicComment.keyLocation.startOffset, magicComment.keyLocation.length).toJavaString();
456+
String value = rubySource.getTStringWithEncoding()
457+
.substring(magicComment.valueLocation.startOffset, magicComment.valueLocation.length)
458+
.toJavaString();
459+
if (RubyLexer.isMagicTruffleRubyPrimitivesComment(name)) {
460+
configuration.allowTruffleRubyPrimitives = value.equalsIgnoreCase("true");
461+
}
462+
}
463+
459464
return parseResult.value;
460465
// YARP end
461466

0 commit comments

Comments
 (0)