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); }
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); }
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); }
/** * Attempt to consume this current token as long as it matches the expected character, or throw an exception if the token does * not match. * * @param expected the expected character 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( char expected ) throws ParsingException, IllegalStateException { if (completed) { String msg = CommonI18n.noMoreContentButWasExpectingCharacter.text(expected); throw new ParsingException(tokens.get(tokens.size() - 1).position(), msg); } // Get the value from the current token ... if (!currentToken().matches(expected)) { String found = currentToken().value(); Position pos = currentToken().position(); String fragment = generateFragment(); String msg = CommonI18n.unexpectedCharacter.text(expected, found, pos.getLine(), pos.getColumn(), fragment); throw new ParsingException(pos, msg); } moveToNextToken(); }
/** * 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); } }
/** * Attempt to consume this current token as long as it matches the expected character, or throw an exception if the token does * not match. * * @param expected the expected character 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( char expected ) throws ParsingException, IllegalStateException { if (completed) { String msg = CommonI18n.noMoreContentButWasExpectingCharacter.text(expected); throw new ParsingException(tokens.get(tokens.size() - 1).position(), msg); } // Get the value from the current token ... if (!currentToken().matches(expected)) { String found = currentToken().value(); Position pos = currentToken().position(); String fragment = generateFragment(); String msg = CommonI18n.unexpectedCharacter.text(expected, found, pos.getLine(), pos.getColumn(), fragment); throw new ParsingException(pos, msg); } moveToNextToken(); }
/** * Convert the value of this token to a long, 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 a long * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public long consumeLong() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String value = currentToken().value(); try { long result = Long.parseLong(value); moveToNextToken(); return result; } catch (NumberFormatException e) { Position position = currentToken().position(); String msg = CommonI18n.expectingValidLongAtLineAndColumn.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); } }
/** * Convert the value of this token to a long, 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 a long * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public long consumeLong() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String value = currentToken().value(); try { long result = Long.parseLong(value); moveToNextToken(); return result; } catch (NumberFormatException e) { Position position = currentToken().position(); String msg = CommonI18n.expectingValidLongAtLineAndColumn.text(value, position.getLine(), position.getColumn()); throw new ParsingException(position, msg); } }
/** * Convert the value of this token to a long, 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 a long * @throws IllegalStateException if this method was called before the stream was {@link #start() started} */ public long consumeLong() throws ParsingException, IllegalStateException { if (completed) throwNoMoreContent(); // Get the value from the current token ... String value = currentToken().value(); try { long result = Long.parseLong(value); moveToNextToken(); return result; } catch (NumberFormatException e) { Position position = currentToken().position(); String msg = CommonI18n.expectingValidLongAtLineAndColumn.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); } }
/** * 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 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 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); } }
/** * Get the position of the previous token. * * @return the previous token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position previousPosition() { return previousToken().position(); }
/** * Get the position of the previous token. * * @return the previous token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position previousPosition() { return previousToken().position(); }
/** * Get the position of the next (or current) token. * * @return the current token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position nextPosition() { return currentToken().position(); }
/** * Get the position of the next (or current) token. * * @return the current token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position nextPosition() { return currentToken().position(); }
/** * Get the position of the previous token. * * @return the previous token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position previousPosition() { return previousToken().position(); }
/** * Get the position of the next (or current) token. * * @return the current token's position; never null * @throws IllegalStateException if this method was called before the stream was {@link #start() started} * @throws NoSuchElementException if there is no previous token */ public Position nextPosition() { return currentToken().position(); }