Package org.jparsec

Class ParseContext

java.lang.Object
org.jparsec.ParseContext
Direct Known Subclasses:
ParserState, ScannerState

abstract class ParseContext extends Object
Represents the context state during parsing.
  • Field Details

    • EOF

      static final String EOF
      See Also:
    • module

      final String module
    • source

      final CharSequence source
    • locator

      final SourceLocator locator
    • at

      int at
      The current position of the input. Points to the token array for token level.
    • step

      int step
      The current logical step.
    • result

      Object result
      The current parse result.
    • trace

      private ParseContext.ParserTrace trace
    • currentErrorType

      private ParseContext.ErrorType currentErrorType
    • currentErrorAt

      private int currentErrorAt
    • currentErrorIndex

      private int currentErrorIndex
    • errors

      private final ArrayList<Object> errors
    • encountered

      private String encountered
    • currentErrorNode

      private TreeNode currentErrorNode
    • errorSuppressed

      private boolean errorSuppressed
    • overrideErrorType

      private ParseContext.ErrorType overrideErrorType
  • Constructor Details

  • Method Details

    • withErrorSuppressed

      final boolean withErrorSuppressed(Parser<?> parser)
      Runs parser with error recording suppressed.
    • applyAsDelimiter

      final boolean applyAsDelimiter(Parser<?> parser)
      Runs parser with error recording suppressed.
    • applyNewNode

      final boolean applyNewNode(Parser<?> parser, String name)
      Applies parser as a new tree node with name, and if fails, reports "expecting $name".
    • applyNested

      final boolean applyNested(Parser<?> parser, ParseContext nestedState)
    • repeat

      final boolean repeat(Parser<?> parser, int n)
    • repeat

      final <T> boolean repeat(Parser<? extends T> parser, int n, Collection<T> collection)
    • getTrace

      final ParseContext.ParserTrace getTrace()
    • errorIndex

      final int errorIndex()
      The physical index of the current most relevant error, 0 if none.
    • buildParseTree

      final ParseTree buildParseTree()
    • buildErrorParseTree

      final ParseTree buildErrorParseTree()
    • renderError

      final ParseErrorDetails renderError()
      Only called when rendering the error in ParserException.
    • getEncountered

      private String getEncountered()
    • getInputName

      abstract String getInputName(int pos)
      Returns the string representation of the current input (character or token).
    • isEof

      abstract boolean isEof()
    • getIndex

      final int getIndex()
      Returns the current index in the original source.
    • getToken

      abstract Token getToken()
      Returns the current token. Only applicable to token level parser.
    • peekChar

      abstract char peekChar()
      Peeks the current character. Only applicable to character level parser.
    • toIndex

      abstract int toIndex(int pos)
      Translates the logical position to physical index in the original source.
    • raise

      final void raise(ParseContext.ErrorType type, Object subject)
    • fail

      final void fail(String message)
    • missing

      final void missing(Object what)
    • expected

      final void expected(Object what)
    • unexpected

      final void unexpected(String what)
    • stillThere

      final boolean stillThere(int wasAt, int originalStep)
    • set

      final void set(int step, int at, Object ret)
    • setAt

      final void setAt(int step, int at)
    • next

      final void next()
    • next

      final void next(int n)
    • enableTrace

      final void enableTrace(String rootName)
      Enables parse tree tracing with rootName as the name of the root node.
    • setErrorState

      private void setErrorState(int errorAt, int errorIndex, ParseContext.ErrorType errorType, List<Object> errors)
    • setErrorState

      private void setErrorState(int errorAt, int errorIndex, ParseContext.ErrorType errorType)
    • copyErrorFrom

      private void copyErrorFrom(ParseContext that)
    • characters

      abstract CharSequence characters()
      Reads the characters as input. Only applicable to character level parsers.
    • toString

      public String toString()
      Overrides:
      toString in class Object