Skip to content

Commit

Permalink
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/ast/Match3Node.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;

/**
* Used when a Regexp literal is the RHS of a match call. E.g., "abc" =~ /.+/
*/
public class Match3Node extends Node {
private final Node receiverNode;
private final Node valueNode;
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -2720,9 +2720,8 @@ private String getVarNameFromScopeTree(IRScope scope, int depth, int offset) {
}

public Operand buildMatch3(Match3Node matchNode) {
// This reversal is intentional
Operand receiver = build(matchNode.getValueNode());
Operand value = build(matchNode.getReceiverNode());
Operand receiver = build(matchNode.getReceiverNode());
Operand value = build(matchNode.getValueNode());

return addResultInstr(new MatchInstr(createTemporaryVariable(), receiver, value));
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -261,7 +261,7 @@ public Node getMatchNode(Node firstNode, Node secondNode) {
return new Match2Node(firstNode.getPosition(), firstNode, secondNode);
}
} else if (secondNode instanceof DRegexpNode || secondNode instanceof RegexpNode) {
return new Match3Node(firstNode.getPosition(), secondNode, firstNode);
return new Match3Node(firstNode.getPosition(), firstNode, secondNode);
}

return getOperatorCallNode(firstNode, "=~", secondNode);
Original file line number Diff line number Diff line change
@@ -1864,10 +1864,8 @@ public RubyNode visitMatch2Node(org.jruby.ast.Match2Node node) {
public RubyNode visitMatch3Node(org.jruby.ast.Match3Node node) {
// Triggered when a Regexp literal is the RHS of an expression.

// This looks weird, but the receiver and value nodes are reversed by the time they get to us, so we need to
// reverse them back in the CallNode.
final org.jruby.ast.Node argsNode = buildArrayNode(node.getPosition(), node.getReceiverNode());
final org.jruby.ast.Node callNode = new CallNode(node.getPosition(), node.getValueNode(), "=~", argsNode, null);
final org.jruby.ast.Node argsNode = buildArrayNode(node.getPosition(), node.getValueNode());
final org.jruby.ast.Node callNode = new CallNode(node.getPosition(), node.getReceiverNode(), "=~", argsNode, null);
return callNode.accept(this);
}

0 comments on commit f07a4b7

Please sign in to comment.