}
@Override
public Node getMatchNode(Node firstNode, Node secondNode) {
if (firstNode instanceof DRegexpNode) {
return new Match2Node(firstNode.getPosition(), firstNode, secondNode);
} else if (firstNode instanceof RegexpNode) {
List<Integer> locals = allocateNamedLocals((RegexpNode) firstNode);
if (locals.size() > 0) {
int[] primitiveLocals = new int[locals.size()];
for (int i = 0; i < primitiveLocals.length; i++) {
primitiveLocals[i] = locals.get(i);
}
return new Match2CaptureNode(firstNode.getPosition(), firstNode, secondNode, primitiveLocals);
} else {
return new Match2Node(firstNode.getPosition(), firstNode, secondNode);
}
} else if (secondNode instanceof DRegexpNode || secondNode instanceof RegexpNode) {
return new Match3Node(firstNode.getPosition(), secondNode, firstNode);
}