Skip to content

Commit

Permalink
Consolidate fixes for #305
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Oct 3, 2014
1 parent cf817d7 commit 6d43d9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
19 changes: 6 additions & 13 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Expand Up @@ -4049,19 +4049,12 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
if (((Node)yyVals[-1+yyTop]) instanceof BlockAcceptingNode && ((BlockAcceptingNode)yyVals[-1+yyTop]).getIterNode() instanceof BlockPassNode) {
throw new SyntaxException(PID.BLOCK_ARG_AND_BLOCK_GIVEN, ((Node)yyVals[-1+yyTop]).getPosition(), lexer.getCurrentLine(), "Both block arg and actual block given.");
}
if (yyVal instanceof IterNode
&& ((Node)yyVals[-1+yyTop]) instanceof ReturnNode
&& ((ReturnNode)yyVals[-1+yyTop]).getValueNode() instanceof BlockAcceptingNode) {
final IterNode iterNode = ((IterNode)yyVal);
final ReturnNode returnNode = ((ReturnNode)yyVals[-1+yyTop]);
final BlockAcceptingNode blockAcceptingNode = (BlockAcceptingNode) returnNode.getValueNode();
blockAcceptingNode.setIterNode(iterNode);
yyVal = returnNode;
} else if (((Node)yyVals[-1+yyTop]) instanceof NonLocalControlFlowNode) {
yyVal = ((BlockAcceptingNode) ((NonLocalControlFlowNode)yyVals[-1+yyTop]).getValueNode()).setIterNode(((IterNode)yyVals[0+yyTop]));
if (((Node)yyVals[-1+yyTop]) instanceof NonLocalControlFlowNode) {
((BlockAcceptingNode) ((NonLocalControlFlowNode)yyVals[-1+yyTop]).getValueNode()).setIterNode(((IterNode)yyVals[0+yyTop]));
} else {
yyVal = ((BlockAcceptingNode)yyVals[-1+yyTop]).setIterNode(((IterNode)yyVals[0+yyTop]));
((BlockAcceptingNode)yyVals[-1+yyTop]).setIterNode(((IterNode)yyVals[0+yyTop]));
}
yyVal = ((Node)yyVals[-1+yyTop]);
((Node)yyVal).setPosition(((Node)yyVals[-1+yyTop]).getPosition());
return yyVal;
}
Expand Down Expand Up @@ -5207,7 +5200,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
}
};
}
// line 2489 "RubyParser.y"
// line 2482 "RubyParser.y"

/** The parse method use an lexer stream and parse it to an AST node
* structure
Expand All @@ -5226,4 +5219,4 @@ public RubyParserResult parse(ParserConfiguration configuration, LexerSource sou
return support.getResult();
}
}
// line 9623 "-"
// line 9616 "-"
15 changes: 4 additions & 11 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Expand Up @@ -1731,19 +1731,12 @@ block_call : command do_block {
if ($1 instanceof BlockAcceptingNode && $<BlockAcceptingNode>1.getIterNode() instanceof BlockPassNode) {
throw new SyntaxException(PID.BLOCK_ARG_AND_BLOCK_GIVEN, $1.getPosition(), lexer.getCurrentLine(), "Both block arg and actual block given.");
}
if ($$ instanceof IterNode
&& $1 instanceof ReturnNode
&& $<ReturnNode>1.getValueNode() instanceof BlockAcceptingNode) {
final IterNode iterNode = $<IterNode>$;
final ReturnNode returnNode = $<ReturnNode>1;
final BlockAcceptingNode blockAcceptingNode = (BlockAcceptingNode) returnNode.getValueNode();
blockAcceptingNode.setIterNode(iterNode);
$$ = returnNode;
} else if ($1 instanceof NonLocalControlFlowNode) {
$$ = ((BlockAcceptingNode) $<NonLocalControlFlowNode>1.getValueNode()).setIterNode($2);
if ($1 instanceof NonLocalControlFlowNode) {
((BlockAcceptingNode) $<NonLocalControlFlowNode>1.getValueNode()).setIterNode($2);
} else {
$$ = $<BlockAcceptingNode>1.setIterNode($2);
$<BlockAcceptingNode>1.setIterNode($2);
}
$$ = $1;
$<Node>$.setPosition($1.getPosition());
}
| block_call dot_or_colon operation2 opt_paren_args {
Expand Down

0 comments on commit 6d43d9f

Please sign in to comment.