@Test public void should_backtrack() { when(machine.length()).thenReturn(0); expression.execute(machine); InOrder inOrder = Mockito.inOrder(machine); inOrder.verify(machine).length(); inOrder.verify(machine).backtrack(); verifyNoMoreInteractions(machine); }
@Override public void execute(Machine machine) { int length = machine.length(); if (length < 2 || machine.tokenAt(0).getType() != from) { machine.backtrack(); return; } int offset = 0; int bridgeLevel = 1; Token token; do { offset++; if (offset >= length) { machine.backtrack(); return; } token = machine.tokenAt(offset); if (token.getType() == from) { bridgeLevel++; } else if (token.getType() == to) { bridgeLevel--; } else { } } while (bridgeLevel != 0); for (int i = 0; i <= offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); }
TokensBridgeExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int length = machine.length(); if (length < 2 || machine.tokenAt(0).getType() != from) { machine.backtrack(); return; } int offset = 0; int bridgeLevel = 1; Token token; do { offset++; if (offset >= length) { machine.backtrack(); return; } token = machine.tokenAt(offset); if (token.getType() == from) { bridgeLevel++; } else if (token.getType() == to) { bridgeLevel--; } else { } } while (bridgeLevel != 0); for (int i = 0; i <= offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } }
TokensBridgeExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int length = machine.length(); if (length < 2 || machine.tokenAt(0).getType() != from) { machine.backtrack(); return; } int offset = 0; int bridgeLevel = 1; Token token; do { offset++; if (offset >= length) { machine.backtrack(); return; } token = machine.tokenAt(offset); if (token.getType() == from) { bridgeLevel++; } else if (token.getType() == to) { bridgeLevel--; } else { } } while (bridgeLevel != 0); for (int i = 0; i <= offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } TokensBridgeExpression(TokenType from, TokenType to); }
TokensBridgeExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int length = machine.length(); if (length < 2 || machine.tokenAt(0).getType() != from) { machine.backtrack(); return; } int offset = 0; int bridgeLevel = 1; Token token; do { offset++; if (offset >= length) { machine.backtrack(); return; } token = machine.tokenAt(offset); if (token.getType() == from) { bridgeLevel++; } else if (token.getType() == to) { bridgeLevel--; } else { } } while (bridgeLevel != 0); for (int i = 0; i <= offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } TokensBridgeExpression(TokenType from, TokenType to); @Override void execute(Machine machine); @Override String toString(); }
TokensBridgeExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { int length = machine.length(); if (length < 2 || machine.tokenAt(0).getType() != from) { machine.backtrack(); return; } int offset = 0; int bridgeLevel = 1; Token token; do { offset++; if (offset >= length) { machine.backtrack(); return; } token = machine.tokenAt(offset); if (token.getType() == from) { bridgeLevel++; } else if (token.getType() == to) { bridgeLevel--; } else { } } while (bridgeLevel != 0); for (int i = 0; i <= offset; i++) { machine.createLeafNode(this, 1); } machine.jump(1); } TokensBridgeExpression(TokenType from, TokenType to); @Override void execute(Machine machine); @Override String toString();  }