Skip to content

Commit

Permalink
Use Prism magic comments in YARPTranslatorDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Nov 22, 2023
1 parent 6277b08 commit 953df20
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/org/truffleruby/parser/YARPTranslatorDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
parserConfiguration.setFrozenStringLiteral(true);
}

RubyLexer.parseMagicComment(rubySource.getTStringWithEncoding(), (name, value) -> {
if (RubyLexer.isMagicTruffleRubyPrimitivesComment(name)) {
parserConfiguration.allowTruffleRubyPrimitives = value.equalsIgnoreCase("true");
}
});

// Parse to the YARP AST

final org.prism.Nodes.Node node;
Expand Down Expand Up @@ -456,6 +450,17 @@ public static org.prism.Nodes.Node parseToYARPAST(RubyContext context, RubyLangu
}
}

for (var magicComment : parseResult.magicComments) {
String name = rubySource.getTStringWithEncoding()
.substring(magicComment.keyLocation.startOffset, magicComment.keyLocation.length).toJavaString();
String value = rubySource.getTStringWithEncoding()
.substring(magicComment.valueLocation.startOffset, magicComment.valueLocation.length)
.toJavaString();
if (RubyLexer.isMagicTruffleRubyPrimitivesComment(name)) {
configuration.allowTruffleRubyPrimitives = value.equalsIgnoreCase("true");
}
}

return parseResult.value;
// YARP end

Expand Down

0 comments on commit 953df20

Please sign in to comment.