/** * Method to allow tokens to be re-used from the start without re-tokenizing content. */ public void rewind() { // recreate the iterator ... tokenIterator = this.tokens.listIterator(); completed = false; currentToken = null; moveToNextToken(); }
/** * Method to allow tokens to be re-used from the start without re-tokenizing content. */ public void rewind() { // recreate the iterator ... tokenIterator = this.tokens.listIterator(); completed = false; currentToken = null; moveToNextToken(); }
/** * Method to allow tokens to be re-used from the start without re-tokenizing content. */ public void rewind() { // recreate the iterator ... tokenIterator = this.tokens.listIterator(); completed = false; currentToken = null; moveToNextToken(); }
/** * Attempt to consume this current token if it matches the expected value, and return whether this method was indeed able to * consume the token. * * @param expected the expected value of the current token token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( char expected ) throws IllegalStateException { if (!matches(expected)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected value, and return whether this method was indeed able to * consume the token. * * @param expected the expected value of the current token token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( char expected ) throws IllegalStateException { if (!matches(expected)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected value, and return whether this method was indeed able to * consume the token. * * @param expected the expected value of the current token token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( char expected ) throws IllegalStateException { if (!matches(expected)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected token type, and return whether this method was indeed able * to consume the token. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected type as a wildcard. * </p> * * @param expectedType the expected token type of the current token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( int expectedType ) throws IllegalStateException { if (!matches(expectedType)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected value, and return whether this method was indeed able to * consume the token. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected value as a wildcard. * </p> * * @param expected the expected value of the current token token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( String expected ) throws IllegalStateException { if (!matches(expected)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected token type, and return whether this method was indeed able * to consume the token. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected type as a wildcard. * </p> * * @param expectedType the expected token type of the current token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( int expectedType ) throws IllegalStateException { if (!matches(expectedType)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected value, and return whether this method was indeed able to * consume the token. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected value as a wildcard. * </p> * * @param expected the expected value of the current token token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( String expected ) throws IllegalStateException { if (!matches(expected)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected value, and return whether this method was indeed able to * consume the token. * <p> * The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected value as a wildcard. * </p> * * @param expected the expected value of the current token token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( String expected ) throws IllegalStateException { if (!matches(expected)) return false; moveToNextToken(); return true; }
/** * Attempt to consume this current token if it matches the expected token type, and return whether this method was indeed able * to consume the token. * <p> * The {@link #ANY_TYPE ANY_TYPE} constant can be used in the expected type as a wildcard. * </p> * * @param expectedType the expected token type of the current token * @return true if the current token did match and was consumed, or false if the current token did not match and therefore was * not consumed * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean canConsume( int expectedType ) throws IllegalStateException { if (!matches(expectedType)) return false; moveToNextToken(); return true; }
/** * Return the value of this token and move to the next token. * * @return the value of the current token * @throws ParsingException if there is no such token to consume * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public String consume() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String result = currentToken().value(); moveToNextToken(); return result; }
/** * Return the value of this token and move to the next token. * * @return the value of the current token * @throws ParsingException if there is no such token to consume * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public String consume() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String result = currentToken().value(); moveToNextToken(); return result; }
/** * Return the value of this token and move to the next token. * * @return the value of the current token * @throws ParsingException if there is no such token to consume * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public String consume() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String result = currentToken().value(); moveToNextToken(); return result; }
/** * Begin the token stream, including (if required) the tokenization of the input content. * * @return this object for easy method chaining; never null * @throws ParsingException if an error occurs during tokenization of the content */ public TokenStream start() throws ParsingException { // Create the tokens ... if (tokens == null) { TokenFactory tokenFactory = caseSensitive ? new CaseSensitiveTokenFactory() : new CaseInsensitiveTokenFactory(); CharacterStream characterStream = new CharacterArrayStream(inputContent); tokenizer.tokenize(characterStream, tokenFactory); this.tokens = initializeTokens(tokenFactory.getTokens()); } // Create the iterator ... tokenIterator = this.tokens.listIterator(); moveToNextToken(); return this; }
/** * Begin the token stream, including (if required) the tokenization of the input content. * * @return this object for easy method chaining; never null * @throws ParsingException if an error occurs during tokenization of the content */ public TokenStream start() throws ParsingException { // Create the tokens ... if (tokens == null) { TokenFactory tokenFactory = caseSensitive ? new CaseSensitiveTokenFactory() : new CaseInsensitiveTokenFactory(); CharacterStream characterStream = new CharacterArrayStream(inputContent); tokenizer.tokenize(characterStream, tokenFactory); this.tokens = initializeTokens(tokenFactory.getTokens()); } // Create the iterator ... tokenIterator = this.tokens.listIterator(); moveToNextToken(); return this; }
/** * Begin the token stream, including (if required) the tokenization of the input content. * * @return this object for easy method chaining; never null * @throws ParsingException if an error occurs during tokenization of the content */ public TokenStream start() throws ParsingException { // Create the tokens ... if (tokens == null) { TokenFactory tokenFactory = caseSensitive ? new CaseSensitiveTokenFactory() : new CaseInsensitiveTokenFactory(); CharacterStream characterStream = new CharacterArrayStream(inputContent); tokenizer.tokenize(characterStream, tokenFactory); this.tokens = initializeTokens(tokenFactory.getTokens()); } // Create the iterator ... tokenIterator = this.tokens.listIterator(); moveToNextToken(); return this; }
/** * Convert the value of this token to an integer, return it, and move to the next token. * * @return the current token's value, converted to an integer * @throws ParsingException if there is no such token to consume, or if the token cannot be converted to an integer * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public int consumeInteger() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String value = currentToken().value(); try { int result = Integer.parseInt(value); moveToNextToken(); return result; } catch (NumberFormatException e) { Position position = currentToken().position(); String msg = CommonI18n.expectingValidIntegerAtLineAndColumn.text(value, position.getLine(), position.getColumn()); throw new ParsingException(position, msg); } }
/** * Convert the value of this token to an integer, return it, and move to the next token. * * @return the current token's value, converted to an integer * @throws ParsingException if there is no such token to consume, or if the token cannot be converted to an integer * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public boolean consumeBoolean() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String value = currentToken().value(); try { boolean result = Boolean.parseBoolean(value); moveToNextToken(); return result; } catch (NumberFormatException e) { Position position = currentToken().position(); String msg = CommonI18n.expectingValidBooleanAtLineAndColumn.text(value, position.getLine(), position.getColumn()); throw new ParsingException(position, msg); } }