File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
spec/tags/truffle/parsing
src/main/java/org/truffleruby/parser Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 1
- fails:Parsing a BEGIN block (BEGIN { ... }) case is parsed correctly
2
1
fails:Parsing a For operator (for ... in ... operator) case is parsed correctly
3
2
4
3
# Not supported yet by Prism
Original file line number Diff line number Diff line change @@ -215,6 +215,9 @@ public class YARPTranslator extends AbstractNodeVisitor<RubyNode> {
215
215
"_9"
216
216
};
217
217
218
+ // all the encountered BEGIN {} blocks
219
+ private final ArrayDeque <Nodes .PreExecutionNode > beginBlocksQueue = new ArrayDeque <>();
220
+
218
221
public YARPTranslator (
219
222
RubyLanguage language ,
220
223
TranslatorEnvironment environment ,
@@ -2440,12 +2443,22 @@ public RubyNode visitPostExecutionNode(Nodes.PostExecutionNode node) {
2440
2443
2441
2444
@ Override
2442
2445
public RubyNode visitPreExecutionNode (Nodes .PreExecutionNode node ) {
2443
- return defaultVisit (node );
2446
+ beginBlocksQueue .add (node );
2447
+ return null ;
2444
2448
}
2445
2449
2446
2450
@ Override
2447
2451
public RubyNode visitProgramNode (Nodes .ProgramNode node ) {
2448
- return node .statements .accept (this );
2452
+ final RubyNode sequence = node .statements .accept (this );
2453
+
2454
+ // add BEGIN {} blocks at the very beginning of the program
2455
+ ArrayList <RubyNode > nodes = new ArrayList <>();
2456
+ for (var begin : beginBlocksQueue ) {
2457
+ nodes .add (begin .statements .accept (this ));
2458
+ }
2459
+
2460
+ nodes .add (sequence );
2461
+ return sequence (node , nodes );
2449
2462
}
2450
2463
2451
2464
@ Override
You can’t perform that action at this time.
0 commit comments