Skip to content

Commit

Permalink
Store block local variables in the AST.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Jan 11, 2016
1 parent 79cc600 commit e6da2d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/ast/ArgsNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class ArgsNode extends Node {
protected final ArgumentNode restArgNode;
private final KeywordRestArgNode keyRest;
private final BlockArgNode blockArgNode;
private ListNode blockLocalVariables = null;

private static final Node[] NO_ARGS = new Node[] {};
/**
Expand Down Expand Up @@ -271,4 +272,12 @@ public int getRequiredKeywordCount() {
}
return count;
}

public ListNode getBlockLocalVariables() {
return blockLocalVariables;
}

public void setBlockLocalVariables(ListNode blockLocalVariables) {
this.blockLocalVariables = blockLocalVariables;
}
}
14 changes: 8 additions & 6 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
states[407] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = support.new_args(lexer.getPosition(), null, null, null, null, (ArgsTailHolder) null);
((ArgsNode) yyVal).setBlockLocalVariables((ListNode) ((Node)yyVals[-1+yyTop]));
return yyVal;
}
};
Expand All @@ -3987,6 +3988,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
states[409] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = ((ArgsNode)yyVals[-2+yyTop]);
((ArgsNode) yyVal).setBlockLocalVariables((ListNode) ((Node)yyVals[-1+yyTop]));
return yyVal;
}
};
Expand All @@ -3998,25 +4000,25 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[411] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = null;
yyVal = ((ListNode)yyVals[-1+yyTop]);
return yyVal;
}
};
states[412] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = null;
yyVal = support.newArrayNode(((Node)yyVals[0+yyTop]).getPosition(), ((Node)yyVals[0+yyTop]));
return yyVal;
}
};
states[413] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = null;
yyVal = ((ListNode)yyVals[-2+yyTop]).add(((Node)yyVals[0+yyTop]));
return yyVal;
}
};
states[414] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
support.new_bv(((String)yyVals[0+yyTop]));
yyVal = support.new_bv(((String)yyVals[0+yyTop]));
return yyVal;
}
};
Expand Down Expand Up @@ -5299,7 +5301,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
}
};
}
// line 2527 "RubyParser.y"
// line 2529 "RubyParser.y"

/** The parse method use an lexer stream and parse it to an AST node
* structure
Expand All @@ -5314,4 +5316,4 @@ public RubyParserResult parse(ParserConfiguration configuration) throws IOExcept
return support.getResult();
}
}
// line 9907 "-"
// line 9909 "-"
14 changes: 8 additions & 6 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ public class RubyParser {
%type <Node> fitem
// ENEBO: begin all new types
%type <Node> f_arg_item
%type <Node> bv_decls
%type <ListNode> bv_decls
%type <Node> opt_bv_decl lambda_body
%type <LambdaNode> lambda
%type <Node> mlhs_inner f_block_opt for_var
%type <Node> opt_call_args f_marg f_margs
%type <String> bvar
%type <Node> bvar
// ENEBO: end all new types

%type <String> rparen rbracket reswords f_bad_arg
Expand Down Expand Up @@ -1671,32 +1671,34 @@ opt_block_param : none {

block_param_def : tPIPE opt_bv_decl tPIPE {
$$ = support.new_args(lexer.getPosition(), null, null, null, null, (ArgsTailHolder) null);
((ArgsNode) $$).setBlockLocalVariables((ListNode) $2);
}
| tOROP {
$$ = support.new_args(lexer.getPosition(), null, null, null, null, (ArgsTailHolder) null);
}
| tPIPE block_param opt_bv_decl tPIPE {
$$ = $2;
((ArgsNode) $$).setBlockLocalVariables((ListNode) $3);
}

// shadowed block variables....
opt_bv_decl : opt_nl {
$$ = null;
}
| opt_nl ';' bv_decls opt_nl {
$$ = null;
$$ = $3;
}

// ENEBO: This is confusing...
bv_decls : bvar {
$$ = null;
$$ = support.newArrayNode($1.getPosition(), $1);
}
| bv_decls ',' bvar {
$$ = null;
$$ = $1.add($3);
}

bvar : tIDENTIFIER {
support.new_bv($1);
$$ = support.new_bv($1);
}
| f_bad_arg {
$$ = null;
Expand Down

0 comments on commit e6da2d8

Please sign in to comment.