Class Parser

java.lang.Object
com.northconcepts.datapipeline.core.Parser
All Implemented Interfaces:
IParser

public class Parser extends Object implements IParser
An IParser over a Reader that buffers characters as needed for lookahead.
  • Field Summary

    Fields inherited from interface com.northconcepts.datapipeline.core.IParser

    EOF
  • Constructor Summary

    Constructors
    Constructor
    Description
    Parser(Reader reader)
     
    Parser(String text)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    void
    consume(int count)
     
    void
     
    void
    consumeWhitespace(char[] exception)
    Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.
    void
    consumeWhitespace(int exception)
    Skips spaces and tabs at the current position, stopping early at the given character.
    void
    Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.
    exception(Throwable exception)
    Wraps the exception in a DataException and adds the parser's buffer and position as properties.
    long
    Returns the number of characters consumed so far (within the current line for LineParser).
    void
    match(char expectedChar)
    Consumes the next character, throwing a DataException if it is not the expected one.
    void
    match(char[] expectedString)
    Consumes the expected string, throwing a DataException at the first character that differs.
    void
    match(char[] expectedString, String failureMessage)
    Consumes the expected string, throwing a DataException prefixed with failureMessage at the first character that differs.
    void
    match(char expectedChar, String failureMessage)
    Consumes the next character, throwing a DataException prefixed with failureMessage if it is not the expected one.
    void
    match(CharSequence expectedString)
    Consumes the expected string, throwing a DataException at the first character that differs.
    void
    match(CharSequence expectedString, String failureMessage)
    Consumes the expected string, throwing a DataException prefixed with failureMessage at the first character that differs.
    matchUntil(char terminatingChar)
    Consumes and returns the text before the terminating character, then consumes the terminator; throws a DataException if the input ends first.
    matchUntil(char terminatingChar, String failureMessage)
    Consumes and returns the text before the terminating character, then consumes the terminator; throws a DataException prefixed with failureMessage if the input ends first.
    Consumes and returns all remaining characters (of the current line for LineParser).
    int
    peek(int index)
    Returns the character at the given 0-based offset ahead without consuming it, or IParser.EOF past the end of the input.
    peekSequence(int offset, int length)
    Returns up to length characters starting at the given lookahead offset without consuming them; fewer if the input ends first.
    boolean
    peekString(char[] lookahead)
    Indicates if the upcoming characters match the given string, without consuming them.
    boolean
    Indicates if the upcoming characters match the given string, without consuming them.
    int
    peekStringArray(char[][] lookahead)
    Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.
    int
    peekStringArray(char[][] lookahead, int offset)
    Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.
    int
    Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.
    int
    peekStringArray(CharSequence[] lookahead, int offset)
    Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.
    boolean
    peekStringOffset(char[] lookahead, int offset)
    Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.
    boolean
    peekStringOffset(CharSequence lookahead, int offset)
    Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.
    int
    Returns the number of consecutive whitespace characters starting at the given 0-based lookahead offset.
    int
    pop()
    Consumes and returns the next character, or IParser.EOF at the end of the input.
    void
    Discards the already consumed characters from the lookahead buffer.
    boolean
     
    void
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Parser

      public Parser(Reader reader)
    • Parser

      public Parser(String text)
  • Method Details

    • exception

      public DataException exception(Throwable exception)
      Description copied from interface: IParser
      Wraps the exception in a DataException and adds the parser's buffer and position as properties.
      Specified by:
      exception in interface IParser
    • ready

      public boolean ready() throws IOException
      Specified by:
      ready in interface IParser
      Throws:
      IOException
    • getColumn

      public long getColumn()
      Description copied from interface: IParser
      Returns the number of characters consumed so far (within the current line for LineParser).
      Specified by:
      getColumn in interface IParser
    • resetColumn

      public void resetColumn()
    • pruneCache

      public void pruneCache()
      Discards the already consumed characters from the lookahead buffer.
    • peek

      public int peek(int index)
      Description copied from interface: IParser
      Returns the character at the given 0-based offset ahead without consuming it, or IParser.EOF past the end of the input.
      Specified by:
      peek in interface IParser
    • peekWhitespaceLength

      public int peekWhitespaceLength(int index)
      Description copied from interface: IParser
      Returns the number of consecutive whitespace characters starting at the given 0-based lookahead offset.
      Specified by:
      peekWhitespaceLength in interface IParser
    • peekSequence

      public CharSequence peekSequence(int offset, int length)
      Description copied from interface: IParser
      Returns up to length characters starting at the given lookahead offset without consuming them; fewer if the input ends first.
      Specified by:
      peekSequence in interface IParser
    • peekString

      public boolean peekString(CharSequence lookahead)
      Description copied from interface: IParser
      Indicates if the upcoming characters match the given string, without consuming them.
      Specified by:
      peekString in interface IParser
    • peekStringOffset

      public boolean peekStringOffset(CharSequence lookahead, int offset)
      Description copied from interface: IParser
      Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.
      Specified by:
      peekStringOffset in interface IParser
    • peekStringArray

      public int peekStringArray(CharSequence... lookahead)
      Description copied from interface: IParser
      Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.
      Specified by:
      peekStringArray in interface IParser
    • peekStringArray

      public int peekStringArray(CharSequence[] lookahead, int offset)
      Description copied from interface: IParser
      Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.
      Specified by:
      peekStringArray in interface IParser
    • pop

      public int pop()
      Description copied from interface: IParser
      Consumes and returns the next character, or IParser.EOF at the end of the input.
      Specified by:
      pop in interface IParser
    • match

      public void match(char expectedChar, String failureMessage)
      Description copied from interface: IParser
      Consumes the next character, throwing a DataException prefixed with failureMessage if it is not the expected one.
      Specified by:
      match in interface IParser
    • match

      public void match(char expectedChar)
      Description copied from interface: IParser
      Consumes the next character, throwing a DataException if it is not the expected one.
      Specified by:
      match in interface IParser
    • match

      public void match(CharSequence expectedString, String failureMessage)
      Description copied from interface: IParser
      Consumes the expected string, throwing a DataException prefixed with failureMessage at the first character that differs.
      Specified by:
      match in interface IParser
    • match

      public void match(CharSequence expectedString)
      Description copied from interface: IParser
      Consumes the expected string, throwing a DataException at the first character that differs.
      Specified by:
      match in interface IParser
    • matchUntil

      public StringBuilder matchUntil(char terminatingChar)
      Description copied from interface: IParser
      Consumes and returns the text before the terminating character, then consumes the terminator; throws a DataException if the input ends first.
      Specified by:
      matchUntil in interface IParser
    • matchUntil

      public StringBuilder matchUntil(char terminatingChar, String failureMessage)
      Description copied from interface: IParser
      Consumes and returns the text before the terminating character, then consumes the terminator; throws a DataException prefixed with failureMessage if the input ends first.
      Specified by:
      matchUntil in interface IParser
    • matchUntilEof

      public StringBuilder matchUntilEof()
      Description copied from interface: IParser
      Consumes and returns all remaining characters (of the current line for LineParser).
      Specified by:
      matchUntilEof in interface IParser
    • consume

      public void consume()
      Specified by:
      consume in interface IParser
    • consume

      public void consume(int count)
      Specified by:
      consume in interface IParser
    • consumeWhitespace

      public void consumeWhitespace()
      Specified by:
      consumeWhitespace in interface IParser
    • consumeWhitespace

      public void consumeWhitespace(int exception)
      Description copied from interface: IParser
      Skips spaces and tabs at the current position, stopping early at the given character.
      Specified by:
      consumeWhitespace in interface IParser
    • consumeWhitespace

      public void consumeWhitespace(CharSequence exception)
      Description copied from interface: IParser
      Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.
      Specified by:
      consumeWhitespace in interface IParser
    • close

      public void close()
      Specified by:
      close in interface IParser
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • peekString

      public boolean peekString(char[] lookahead)
      Description copied from interface: IParser
      Indicates if the upcoming characters match the given string, without consuming them.
      Specified by:
      peekString in interface IParser
    • peekStringOffset

      public boolean peekStringOffset(char[] lookahead, int offset)
      Description copied from interface: IParser
      Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.
      Specified by:
      peekStringOffset in interface IParser
    • peekStringArray

      public int peekStringArray(char[][] lookahead)
      Description copied from interface: IParser
      Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.
      Specified by:
      peekStringArray in interface IParser
    • peekStringArray

      public int peekStringArray(char[][] lookahead, int offset)
      Description copied from interface: IParser
      Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.
      Specified by:
      peekStringArray in interface IParser
    • match

      public void match(char[] expectedString, String failureMessage)
      Description copied from interface: IParser
      Consumes the expected string, throwing a DataException prefixed with failureMessage at the first character that differs.
      Specified by:
      match in interface IParser
    • match

      public void match(char[] expectedString)
      Description copied from interface: IParser
      Consumes the expected string, throwing a DataException at the first character that differs.
      Specified by:
      match in interface IParser
    • consumeWhitespace

      public void consumeWhitespace(char[] exception)
      Description copied from interface: IParser
      Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.
      Specified by:
      consumeWhitespace in interface IParser