Class CharacterParser

java.lang.Object
org.projog.core.parser.CharacterParser

final class CharacterParser extends Object
Reads characters from a BufferedReader.

Provides details of current line and column number being parsed.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final BufferedReader
     
    private int
    The position, within the current line, of the character being parsed.
    private String
     
    private static final int
     
    private int
    The line number of the current line being parsed.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) int
    Returns the index, in the line currently being parsed, of the character that will be returned by the next call to getNext().
    (package private) String
    Returns the entire contents of the line currently being parsed.
    (package private) int
    Returns the line number of the line currently being parsed.
    (package private) int
    Reads a single character.
    (package private) int
    Reads a single character but does not consume it.
    (package private) void
    Moves the parser back one character.
    (package private) void
    rewind(int numberOfCharacters)
    Moves the parser back by the specified number of characters.
    (package private) void
    Skips the remainder of the line currently being parsed.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • END_OF_STREAM

      private static final int END_OF_STREAM
      See Also:
    • br

      private final BufferedReader br
    • currentLine

      private String currentLine
    • lineNumber

      private int lineNumber
      The line number of the current line being parsed.

      Required in order to provide useful information if a ParserException is 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 ParserException is thrown.

  • Constructor Details

  • 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 to getNext() 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 to getNext().