Class CharacterParser
java.lang.Object
org.projog.core.parser.CharacterParser
Reads characters from a
BufferedReader.
Provides details of current line and column number being parsed.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BufferedReaderprivate intThe position, within the current line, of the character being parsed.private Stringprivate static final intprivate intThe line number of the current line being parsed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) intReturns the index, in the line currently being parsed, of the character that will be returned by the next call togetNext().(package private) StringgetLine()Returns the entire contents of the line currently being parsed.(package private) intReturns the line number of the line currently being parsed.(package private) intgetNext()Reads a single character.(package private) intpeek()Reads a single character but does not consume it.(package private) voidrewind()Moves the parser back one character.(package private) voidrewind(int numberOfCharacters) Moves the parser back by the specified number of characters.(package private) voidskipLine()Skips the remainder of the line currently being parsed.
-
Field Details
-
END_OF_STREAM
private static final int END_OF_STREAM- See Also:
-
br
-
currentLine
-
lineNumber
private int lineNumberThe line number of the current line being parsed.Required in order to provide useful information if a
ParserExceptionis thrown. -
columnNumber
private int columnNumberThe position, within the current line, of the character being parsed.Required in order to provide useful information if a
ParserExceptionis thrown.
-
-
Constructor Details
-
CharacterParser
CharacterParser(BufferedReader br)
-
-
Method Details
-
getNext
int getNext()Reads a single character.Every call to
getNext()causes the parser to move forward one character - meaning that by making repeated calls togetNext()all characters in the the underlying stream represented by this object will be returned.- Returns:
- The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
- Throws:
ParserException- if an I/O error occurs- See Also:
-
peek
int peek()Reads a single character but does not consume it.- Returns:
- The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
- Throws:
ParserException- if an I/O error occurs- See Also:
-
rewind
void rewind()Moves the parser back one character.- Throws:
ParserException- if attempting to rewind back past the start of the current line
-
rewind
void rewind(int numberOfCharacters) Moves the parser back by the specified number of characters.- Throws:
ParserException- if attempting to rewind back past the start of the current line
-
skipLine
void skipLine()Skips the remainder of the line currently being parsed. -
getLine
String getLine()Returns the entire contents of the line currently being parsed. -
getLineNumber
int getLineNumber()Returns the line number of the line currently being parsed. -
getColumnNumber
int getColumnNumber()Returns the index, in the line currently being parsed, of the character that will be returned by the next call togetNext().
-