Skip to content

Commit

Permalink
Parser changes for #2960: Block Parameter Scoping (vs Ruby).
Browse files Browse the repository at this point in the history
A followup commit will try and address the depth change hacks in IR
but we still need to create some variables for magic vars in evals
and for flip flop.  So unfornately just deleting that fix code in
IR breaks those things.  Leaving the IR code does not break our
compat so it more of a maintenance issue...
enebo committed Jan 21, 2016
1 parent 7a20145 commit e699ba3
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -235,6 +235,12 @@ public Node appendToBlock(Node head, Node tail) {
return head;
}

// We know it has to be tLABEL or tIDENTIFIER so none of the other assignable logic is needed
public AssignableNode assignableInCurr(String name, Node value) {
currentScope.addVariableThisScope(name);
return currentScope.assign(lexer.getPosition(), name, makeNullNil(value));
}

public Node getOperatorCallNode(Node firstNode, String operator) {
checkExpression(firstNode);

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Original file line number Diff line number Diff line change
@@ -3756,7 +3756,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[371] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = support.assignableLabelOrIdentifier(((String)yyVals[0+yyTop]), NilImplicitNode.NIL);
yyVal = support.assignableInCurr(((String)yyVals[0+yyTop]), NilImplicitNode.NIL);
return yyVal;
}
};
@@ -3786,13 +3786,13 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[376] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-3+yyTop]).getPosition(), ((ListNode)yyVals[-3+yyTop]), support.assignableLabelOrIdentifier(((String)yyVals[0+yyTop]), null), null);
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-3+yyTop]).getPosition(), ((ListNode)yyVals[-3+yyTop]), support.assignableInCurr(((String)yyVals[0+yyTop]), null), null);
return yyVal;
}
};
states[377] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-5+yyTop]).getPosition(), ((ListNode)yyVals[-5+yyTop]), support.assignableLabelOrIdentifier(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-5+yyTop]).getPosition(), ((ListNode)yyVals[-5+yyTop]), support.assignableInCurr(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
return yyVal;
}
};
@@ -3810,13 +3810,13 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[380] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier(((String)yyVals[0+yyTop]), null), null);
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr(((String)yyVals[0+yyTop]), null), null);
return yyVal;
}
};
states[381] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
return yyVal;
}
};
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -1552,7 +1552,7 @@ for_var : lhs
}

f_marg : f_norm_arg {
$$ = support.assignableLabelOrIdentifier($1, NilImplicitNode.NIL);
$$ = support.assignableInCurr($1, NilImplicitNode.NIL);
}
| tLPAREN f_margs rparen {
$$ = $2;
@@ -1570,10 +1570,10 @@ f_margs : f_marg_list {
$$ = new MultipleAsgnNode($1.getPosition(), $1, null, null);
}
| f_marg_list ',' tSTAR f_norm_arg {
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableLabelOrIdentifier($4, null), null);
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableInCurr($4, null), null);
}
| f_marg_list ',' tSTAR f_norm_arg ',' f_marg_list {
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableLabelOrIdentifier($4, null), $6);
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableInCurr($4, null), $6);
}
| f_marg_list ',' tSTAR {
$$ = new MultipleAsgnNode($1.getPosition(), $1, new StarNode(lexer.getPosition()), null);
@@ -1582,10 +1582,10 @@ f_margs : f_marg_list {
$$ = new MultipleAsgnNode($1.getPosition(), $1, new StarNode(lexer.getPosition()), $5);
}
| tSTAR f_norm_arg {
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier($2, null), null);
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr($2, null), null);
}
| tSTAR f_norm_arg ',' f_marg_list {
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier($2, null), $4);
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr($2, null), $4);
}
| tSTAR {
$$ = new MultipleAsgnNode(lexer.getPosition(), null, new StarNode(lexer.getPosition()), null);

0 comments on commit e699ba3

Please sign in to comment.