if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpected != ANY_VALUE && !token.matches(currentExpected)) return false; for (String nextExpected : expectedForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
protected void throwNoMoreContent() throws ParsingException { String msg = CommonI18n.noMoreContent.text(); Position pos = tokens.isEmpty() ? new Position(-1, 1, 0) : tokens.get(tokens.size() - 1).position(); throw new ParsingException(pos, msg); }
token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpected != ANY_VALUE && !token.matches(currentExpected)) return false; for (String nextExpected : expectedForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpected != ANY_VALUE && !token.matches(currentExpected)) return false; for (String nextExpected : expectedForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false;
/** * Determine if the next few tokens have the supplied types. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected values as a wildcard. * </p> * * @param currentExpectedType the expected type of the current token * @param expectedTypeForNextTokens the expected type for the following tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int currentExpectedType, int... expectedTypeForNextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpectedType != ANY_TYPE && currentToken().type() != currentExpectedType) return false; for (int nextExpectedType : expectedTypeForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpectedType == ANY_TYPE) continue; if (token.type() != nextExpectedType) return false; } return true; }
/** * Attempt to consume this current token as long as it matches the expected value, or throw an exception if the token does not * match. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard. * </p> * * @param expected the expected value of the current token * @throws ParsingException if the current token doesn't match the supplied value * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public void consume( String expected ) throws ParsingException, IllegalStateException { if (completed) { String msg = CommonI18n.noMoreContentButWasExpectingToken.text(expected); throw new ParsingException(tokens.get(tokens.size() - 1).position(), msg); } // Get the value from the current token ... if (expected != ANY_VALUE && !currentToken().matches(expected)) { String found = currentToken().value(); Position pos = currentToken().position(); String fragment = generateFragment(); String msg = CommonI18n.unexpectedToken.text(expected, found, pos.getLine(), pos.getColumn(), fragment); throw new ParsingException(pos, msg); } moveToNextToken(); }
/** * Attempt to consume this current token as long as it matches the expected character, or throw an exception if the token does * not match. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected values as a wildcard. * </p> * * @param expectedType the expected token type of the current token * @throws ParsingException if the current token doesn't match the supplied value * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public void consume( int expectedType ) throws ParsingException, IllegalStateException { if (completed) { String msg = CommonI18n.noMoreContentButWasExpectingTokenType.text(expectedType); throw new ParsingException(tokens.get(tokens.size() - 1).position(), msg); } // Get the value from the current token ... if (expectedType != ANY_TYPE && currentToken().type() != expectedType) { String found = currentToken().value(); Position pos = currentToken().position(); String fragment = generateFragment(); String msg = CommonI18n.unexpectedTokenType.text(expectedType, found, pos.getLine(), pos.getColumn(), fragment); throw new ParsingException(pos, msg); } moveToNextToken(); }
/** * Determine if the next few tokens match the expected values. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard. * </p> * * @param currentExpected the expected value of the current token * @param expectedForNextTokens the expected values for the following tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( String currentExpected, String... expectedForNextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpected != ANY_VALUE && !token.matches(currentExpected)) return false; for (String nextExpected : expectedForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false; } return true; }
/** * Determine if the next few tokens have the supplied types. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected values as a wildcard. * </p> * * @param currentExpectedType the expected type of the current token * @param expectedTypeForNextTokens the expected type for the following tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int currentExpectedType, int... expectedTypeForNextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpectedType != ANY_TYPE && currentToken().type() != currentExpectedType) return false; for (int nextExpectedType : expectedTypeForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpectedType == ANY_TYPE) continue; if (token.type() != nextExpectedType) return false; } return true; }
/** * Determine if the next few tokens match the expected values. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard. * </p> * * @param currentExpected the expected value of the current token * @param expectedForNextTokens the expected values for the following tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( String currentExpected, String... expectedForNextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpected != ANY_VALUE && !token.matches(currentExpected)) return false; for (String nextExpected : expectedForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpected == ANY_VALUE) continue; if (!token.matches(nextExpected)) return false; } return true; }
/** * Determine if the next few tokens have the supplied types. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected values as a wildcard. * </p> * * @param currentExpectedType the expected type of the current token * @param expectedTypeForNextTokens the expected type for the following tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int currentExpectedType, int... expectedTypeForNextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); if (!iter.hasNext()) return false; Token token = iter.next(); if (currentExpectedType != ANY_TYPE && currentToken().type() != currentExpectedType) return false; for (int nextExpectedType : expectedTypeForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpectedType == ANY_TYPE) continue; if (token.type() != nextExpectedType) return false; } return true; }
/** * Determine if the next few tokens have the supplied types. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected values as a wildcard. * </p> * * @param typesForNextTokens the expected type for each of the next tokens * @return true if the tokens did match, or false otherwise * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean matches( int[] typesForNextTokens ) throws IllegalStateException { if (completed) return false; ListIterator<Token> iter = tokens.listIterator(tokenIterator.previousIndex()); Token token = null; for (int nextExpectedType : typesForNextTokens) { if (!iter.hasNext()) return false; token = iter.next(); if (nextExpectedType == ANY_TYPE) continue; if (!token.matches(nextExpectedType)) return false; } return true; }