Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ast/ForwardingBlockArgNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jruby.ast;

public class ForwardingBlockArgNode extends BlockArgNode {
public ForwardingBlockArgNode(ArgumentNode argNode) {
super(argNode);
}
}
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/ext/ripper/RipperParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
import static org.jruby.lexer.LexingCommon.EXPR_END;
import static org.jruby.lexer.LexingCommon.EXPR_LABEL;
import static org.jruby.util.CommonByteLists.ANON_BLOCK;
import static org.jruby.util.CommonByteLists.FWD_BLOCK;
import static org.jruby.util.CommonByteLists.FWD_KWREST;

public class RipperParser extends RipperParserBase {
public RipperParser(ThreadContext context, IRubyObject ripper, LexerSource source) {
super(context, ripper, source);
}
// line 99 "-"
// line 100 "-"
// %token constants
public static final int keyword_class = 257;
public static final int keyword_module = 258;
Expand Down Expand Up @@ -6437,7 +6438,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
return yyVal;
};
states[771] = (RipperParser p, Object yyVal, ProductionState[] yyVals, int yyTop, int count, int yychar) -> {
yyVal = p.arg_var(p.shadowing_lvar(FWD_BLOCK));
yyVal = p.arg_var(p.shadowing_lvar(ANON_BLOCK));
yyVal = p.dispatch("on_blockarg", p.nil());

return yyVal;
Expand Down Expand Up @@ -6606,7 +6607,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
return yyVal;
};
}
// line 4585 "ripper_RubyParser.out"
// line 4586 "ripper_RubyParser.out"

}
// line 14362 "-"
// line 14363 "-"
13 changes: 7 additions & 6 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
import static org.jruby.lexer.LexingCommon.EXPR_END;
import static org.jruby.lexer.LexingCommon.EXPR_LABEL;
import static org.jruby.util.CommonByteLists.ANON_BLOCK;
import static org.jruby.util.CommonByteLists.FWD_BLOCK;
import static org.jruby.util.CommonByteLists.FWD_KWREST;

public class RubyParser extends RubyParserBase {
public RubyParser(LexerSource source, IRubyWarnings warnings) {
super(warnings); setLexer(new RubyLexer(this, source, warnings));
}
// line 99 "-"
// line 100 "-"
// %token constants
public static final int keyword_class = 257;
public static final int keyword_module = 258;
Expand Down Expand Up @@ -3869,8 +3870,8 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[316] = (RubyParser p, Object yyVal, ProductionState[] yyVals, int yyTop, int count, int yychar) -> {
/*%%%*/
if (!p.local_id(FWD_BLOCK)) p.compile_error("no anonymous block parameter");
yyVal = new BlockPassNode(yyVals[yyTop - count + 1].start(), p.arg_var(FWD_BLOCK));
if (!p.local_id(ANON_BLOCK)) p.compile_error("no anonymous block parameter");
yyVal = new BlockPassNode(yyVals[yyTop - count + 1].start(), p.arg_var(ANON_BLOCK));
/* Changed from MRI*/
/*%
$$ = p.nil();
Expand Down Expand Up @@ -6565,7 +6566,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
return yyVal;
};
states[771] = (RubyParser p, Object yyVal, ProductionState[] yyVals, int yyTop, int count, int yychar) -> {
yyVal = p.arg_var(p.shadowing_lvar(FWD_BLOCK));
yyVal = p.arg_var(p.shadowing_lvar(ANON_BLOCK));
/*%%%*/
yyVal = new BlockArgNode(((ArgumentNode)yyVal));
/* Changed from MRI*/
Expand Down Expand Up @@ -6759,7 +6760,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
return yyVal;
};
}
// line 4738 "parse.y"
// line 4739 "parse.y"

}
// line 14515 "-"
// line 14516 "-"
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import static org.jruby.lexer.LexingCommon.EXPR_ENDFN;
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
import static org.jruby.lexer.LexingCommon.EXPR_END;
import static org.jruby.lexer.LexingCommon.EXPR_LABEL;
import static org.jruby.util.CommonByteLists.ANON_BLOCK;
import static org.jruby.util.CommonByteLists.FWD_BLOCK;
import static org.jruby.util.CommonByteLists.FWD_KWREST;

Expand Down Expand Up @@ -2110,8 +2111,8 @@ block_arg : tAMPER arg_value {
}
| tAMPER {
/*%%%*/
if (!p.local_id(FWD_BLOCK)) p.compile_error("no anonymous block parameter");
$$ = new BlockPassNode(@1.start(), p.arg_var(FWD_BLOCK));
if (!p.local_id(ANON_BLOCK)) p.compile_error("no anonymous block parameter");
$$ = new BlockPassNode(@1.start(), p.arg_var(ANON_BLOCK));
// Changed from MRI
/*%
$$ = p.nil();
Expand Down Expand Up @@ -4625,7 +4626,7 @@ f_block_arg : blkarg_mark tIDENTIFIER {
/*% ripper: blockarg!($2) %*/
}
| blkarg_mark {
$$ = p.arg_var(p.shadowing_lvar(FWD_BLOCK));
$$ = p.arg_var(p.shadowing_lvar(ANON_BLOCK));
/*%%%*/
$$ = new BlockArgNode($<ArgumentNode>$);
// Changed from MRI
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/parser/RubyParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ public ArgsNode new_args(int line, ListNode pre, ListNode optional, RestArgNode
if (tail == null) {
argsNode = new ArgsNode(line, pre, optional, rest, post, null);
} else {
if (tail.getBlockArg() != null && FWD_BLOCK.equals(tail.getBlockArg().getName().getBytes())) {
if (tail.getBlockArg() instanceof ForwardingBlockArgNode) {
if (rest != null) {
yyerror("... after rest argument");
argsNode = new ArgsNode(line, null, null, null, null,
Expand Down Expand Up @@ -1503,7 +1503,8 @@ protected ArgsTailHolder new_args_tail(int line, ListNode keywordArg,
BlockArgNode blockArg = null;
if (block != null) {
ArgumentNode var = arg_var(block);
blockArg = new BlockArgNode(var);

blockArg = block == FWD_BLOCK ? new ForwardingBlockArgNode(var) : new BlockArgNode(var);
}

return new_args_tail(line, keywordArg, keywordRestArgName, blockArg);
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/util/CommonByteLists.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jruby.util;

import org.jcodings.specific.USASCIIEncoding;

/**
* Values which are referenced in multiple places. A ByteList warehouse!
*/
Expand Down Expand Up @@ -40,6 +42,9 @@ public class CommonByteLists {
public static final ByteList FWD_REST = STAR;
public static final ByteList FWD_KWREST = STAR_STAR;
public static final ByteList FWD_BLOCK = AMPERSAND;
// Needs to be different than FWD_BLOCK for object identity comparisons.
public static final ByteList ANON_BLOCK = new ByteList(new byte[] {'&'}, USASCIIEncoding.INSTANCE);

public static final ByteList TAB = new ByteList(new byte[] {'\t'});
public static final ByteList UNDERSCORE = new ByteList(new byte[] {'_'});
public static final ByteList USING_METHOD = new ByteList(new byte[] {'u', 's', 'i', 'n', 'g'});
Expand Down