Package org.projog.core.parser
Class CharacterParser
- java.lang.Object
-
- org.projog.core.parser.CharacterParser
-
final class CharacterParser extends java.lang.ObjectReads characters from aBufferedReader.Provides details of current line and column number being parsed.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.BufferedReaderbrprivate intcolumnNumberThe position, within the current line, of the character being parsed.private java.lang.StringcurrentLineprivate static intEND_OF_STREAMprivate intlineNumberThe line number of the current line being parsed.
-
Constructor Summary
Constructors Constructor Description CharacterParser(java.io.BufferedReader br)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) intgetColumnNumber()Returns the index, in the line currently being parsed, of the character that will be returned by the next call togetNext().(package private) java.lang.StringgetLine()Returns the entire contents of the line currently being parsed.(package private) intgetLineNumber()Returns 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 Detail
-
END_OF_STREAM
private static final int END_OF_STREAM
- See Also:
- Constant Field Values
-
br
private final java.io.BufferedReader br
-
currentLine
private java.lang.String currentLine
-
lineNumber
private int lineNumber
The line number of the current line being parsed.Required in order to provide useful information if a
ParserExceptionis thrown.
-
columnNumber
private int columnNumber
The position, within the current line, of the character being parsed.Required in order to provide useful information if a
ParserExceptionis thrown.
-
-
Method Detail
-
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()
-
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:
getNext()
-
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
java.lang.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().
-
-