/** * Verifies that the actual <code>{@link Rule}</code> partially matches a given input. * * @param prefixToBeMatched the prefix that must be fully matched * @param remainingInput the remainder of the input, which is not to be matched * @return this assertion object. */ public ParserAssert matchesPrefix(String prefixToBeMatched, String remainingInput) { isNotNull(); try { JavaScriptTree tree = (JavaScriptTree) actual.parse(prefixToBeMatched + remainingInput); SyntaxToken lastToken = tree.getLastToken(); if (prefixToBeMatched.length() != lastToken.column() + lastToken.text().length()) { throw new RecognitionException( 0, "Rule '" + getRuleName() + "' should match:\n" + prefixToBeMatched + "\nwhen followed by:\n" + remainingInput); } } catch (RecognitionException e) { throw new RecognitionException( 0, e.getMessage() + "\n" + "Rule '" + getRuleName() + "' should match:\n" + prefixToBeMatched + "\nwhen followed by:\n" + remainingInput); } return this; }
private void parseTillEof(String input) { JavaScriptTree tree = (JavaScriptTree) actual.parse(input); InternalSyntaxToken lastToken = (InternalSyntaxToken) tree.getLastToken(); if (lastToken.toIndex() != input.length()) { throw new RecognitionException( 0, "Did not match till EOF, but till line " + lastToken.line() + ": token \"" + lastToken.text() + "\""); } }