@Test public void should_match2() { Token token0 = token(GenericTokenType.IDENTIFIER, 1); Token token1 = token(GenericTokenType.IDENTIFIER, 1); Token token2 = token(GenericTokenType.IDENTIFIER, 1); Token token3 = token(GenericTokenType.EOF, 1); when(machine.getIndex()).thenReturn(1); when(machine.tokenAt(-1)).thenReturn(token0); when(machine.tokenAt(0)).thenReturn(token1); when(machine.tokenAt(1)).thenReturn(token2); when(machine.tokenAt(2)).thenReturn(token3); expression.execute(machine); InOrder inOrder = Mockito.inOrder(machine); inOrder.verify(machine).getIndex(); inOrder.verify(machine).tokenAt(-1); inOrder.verify(machine).tokenAt(0); inOrder.verify(machine).tokenAt(1); inOrder.verify(machine).tokenAt(2); inOrder.verify(machine, times(2)).createLeafNode(expression, 1); inOrder.verify(machine).jump(1); verifyNoMoreInteractions(machine); }
@Override public void execute(Machine machine) { int currentLine = machine.getIndex() == 0 ? 1 : machine.tokenAt(-1).getLine(); int offset = 0; Token token = machine.tokenAt(offset); while (token.getLine() == currentLine && token.getType() != GenericTokenType.EOF) { offset++; token = machine.tokenAt(offset); } for (int i = 0; i < offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); }
TillNewLineExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int currentLine = machine.getIndex() == 0 ? 1 : machine.tokenAt(-1).getLine(); int offset = 0; Token token = machine.tokenAt(offset); while (token.getLine() == currentLine && token.getType() != GenericTokenType.EOF) { offset++; token = machine.tokenAt(offset); } for (int i = 0; i < offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } }
TillNewLineExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int currentLine = machine.getIndex() == 0 ? 1 : machine.tokenAt(-1).getLine(); int offset = 0; Token token = machine.tokenAt(offset); while (token.getLine() == currentLine && token.getType() != GenericTokenType.EOF) { offset++; token = machine.tokenAt(offset); } for (int i = 0; i < offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } private  TillNewLineExpression(); }
TillNewLineExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int currentLine = machine.getIndex() == 0 ? 1 : machine.tokenAt(-1).getLine(); int offset = 0; Token token = machine.tokenAt(offset); while (token.getLine() == currentLine && token.getType() != GenericTokenType.EOF) { offset++; token = machine.tokenAt(offset); } for (int i = 0; i < offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } private  TillNewLineExpression(); @Override void execute(Machine machine); @Override String toString(); }
TillNewLineExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int currentLine = machine.getIndex() == 0 ? 1 : machine.tokenAt(-1).getLine(); int offset = 0; Token token = machine.tokenAt(offset); while (token.getLine() == currentLine && token.getType() != GenericTokenType.EOF) { offset++; token = machine.tokenAt(offset); } for (int i = 0; i < offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } private  TillNewLineExpression(); @Override void execute(Machine machine); @Override String toString(); static final TillNewLineExpression INSTANCE; }