Top Description Inners Fields Constructors Methods
org.jparsec

pack-priv abstract Class ParseContext

extends Object
Class Inheritance
Known Direct Subclasses
org.jparsec.ParserState, org.jparsec.ScannerState
Static Imports
org.jparsec.internal.util.Checks.checkState

Represents the context state during parsing.
Author
Ben Yu

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
pack-priv static interface
ParseContext.ParserTrace

Allows tracing of parsing progress during error condition, to ease debugging.

Field Summary

Modifier and TypeField and Description
pack-priv int
at

The current position of the input.

private int
private int
private TreeNode
private ParseContext.ErrorType
private String
pack-priv static final String
private final ArrayList<Object>
private boolean
pack-priv final SourceLocator
pack-priv final String
private ParseContext.ErrorType
pack-priv Object
result

The current parse result.

pack-priv final CharSequence
pack-priv int
step

The current logical step.

private ParseContext.ParserTrace

Constructor Summary

AccessConstructor and Description
pack-priv
ParseContext(CharSequence source, int at, String module, SourceLocator locator)

pack-priv
ParseContext(CharSequence source, Object ret, int at, String module, SourceLocator locator)

Method Summary

Modifier and TypeMethod and Description
pack-priv final boolean
applyAsDelimiter(Parser<?> parser)

Runs parser with error recording suppressed.

pack-priv final boolean
applyNested(Parser<?> parser, ParseContext nestedState)

pack-priv final boolean
applyNewNode(Parser<?> parser, String name)

Applies parser as a new tree node with name, and if fails, reports "expecting $name".

pack-priv final ParseTree
pack-priv final ParseTree
pack-priv abstract CharSequence
characters()

Reads the characters as input.

private void
pack-priv final void
enableTrace(final String rootName)

Enables parse tree tracing with rootName as the name of the root node.

pack-priv final int
errorIndex()

The physical index of the current most relevant error, 0 if none.

pack-priv final void
pack-priv final void
fail(String message)

private String
pack-priv final int
getIndex()

Returns the current index in the original source.

pack-priv abstract String
getInputName(int pos)

Returns the string representation of the current input (character or token).

pack-priv abstract Token
getToken()

Returns the current token.

pack-priv final ParseContext.ParserTrace
pack-priv abstract boolean
pack-priv final void
pack-priv final void
next()

pack-priv final void
next(int n)

pack-priv abstract char
peekChar()

Peeks the current character.

pack-priv final void
pack-priv final ParseErrorDetails
renderError()

Only called when rendering the error in ParserException.

pack-priv final boolean
repeat(Parser<?> parser, int n)

pack-priv final <T> boolean
repeat(Parser<? extends T> parser, int n, Collection<T> collection)

pack-priv final void
set(int step, int at, Object ret)

pack-priv final void
setAt(int step, int at)

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

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

pack-priv final boolean
stillThere(int wasAt, int originalStep)

pack-priv abstract int
toIndex(int pos)

Translates the logical position to physical index in the original source.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv final void
pack-priv final boolean
withErrorSuppressed(Parser<?> parser)

Runs parser with error recording suppressed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

atback to summary
pack-priv int at

The current position of the input. Points to the token array for token level.

currentErrorAtback to summary
private int currentErrorAt
currentErrorIndexback to summary
private int currentErrorIndex
currentErrorNodeback to summary
private TreeNode currentErrorNode
currentErrorTypeback to summary
private ParseContext.ErrorType currentErrorType
encounteredback to summary
private String encountered
EOFback to summary
pack-priv static final String EOF
errorsback to summary
private final ArrayList<Object> errors
errorSuppressedback to summary
private boolean errorSuppressed
locatorback to summary
pack-priv final SourceLocator locator
moduleback to summary
pack-priv final String module
overrideErrorTypeback to summary
private ParseContext.ErrorType overrideErrorType
resultback to summary
pack-priv Object result

The current parse result.

sourceback to summary
pack-priv final CharSequence source
stepback to summary
pack-priv int step

The current logical step.

traceback to summary
private ParseContext.ParserTrace trace

Constructor Detail

ParseContextback to summary
pack-priv ParseContext(CharSequence source, int at, String module, SourceLocator locator)
ParseContextback to summary
pack-priv ParseContext(CharSequence source, Object ret, int at, String module, SourceLocator locator)

Method Detail

applyAsDelimiterback to summary
pack-priv final boolean applyAsDelimiter(Parser<?> parser)

Runs parser with error recording suppressed.

applyNestedback to summary
pack-priv final boolean applyNested(Parser<?> parser, ParseContext nestedState)
applyNewNodeback to summary
pack-priv final boolean applyNewNode(Parser<?> parser, String name)

Applies parser as a new tree node with name, and if fails, reports "expecting $name".

buildErrorParseTreeback to summary
pack-priv final ParseTree buildErrorParseTree()
buildParseTreeback to summary
pack-priv final ParseTree buildParseTree()
charactersback to summary
pack-priv abstract CharSequence characters()

Reads the characters as input. Only applicable to character level parsers.

copyErrorFromback to summary
private void copyErrorFrom(ParseContext that)
enableTraceback to summary
pack-priv final void enableTrace(final String rootName)

Enables parse tree tracing with rootName as the name of the root node.

errorIndexback to summary
pack-priv final int errorIndex()

The physical index of the current most relevant error, 0 if none.

expectedback to summary
pack-priv final void expected(Object what)
failback to summary
pack-priv final void fail(String message)
getEncounteredback to summary
private String getEncountered()
getIndexback to summary
pack-priv final int getIndex()

Returns the current index in the original source.

getInputNameback to summary
pack-priv abstract String getInputName(int pos)

Returns the string representation of the current input (character or token).

getTokenback to summary
pack-priv abstract Token getToken()

Returns the current token. Only applicable to token level parser.

getTraceback to summary
pack-priv final ParseContext.ParserTrace getTrace()
isEofback to summary
pack-priv abstract boolean isEof()
missingback to summary
pack-priv final void missing(Object what)
nextback to summary
pack-priv final void next()
nextback to summary
pack-priv final void next(int n)
peekCharback to summary
pack-priv abstract char peekChar()

Peeks the current character. Only applicable to character level parser.

raiseback to summary
pack-priv final void raise(ParseContext.ErrorType type, Object subject)
Annotations
@Private
renderErrorback to summary
pack-priv final ParseErrorDetails renderError()

Only called when rendering the error in ParserException.

repeatback to summary
pack-priv final boolean repeat(Parser<?> parser, int n)
repeatback to summary
pack-priv final <T> boolean repeat(Parser<? extends T> parser, int n, Collection<T> collection)
setback to summary
pack-priv final void set(int step, int at, Object ret)
setAtback to summary
pack-priv final void setAt(int step, int at)
setErrorStateback to summary
private void setErrorState(int errorAt, int errorIndex, ParseContext.ErrorType errorType, List<Object> errors)
setErrorStateback to summary
private void setErrorState(int errorAt, int errorIndex, ParseContext.ErrorType errorType)
stillThereback to summary
pack-priv final boolean stillThere(int wasAt, int originalStep)
toIndexback to summary
pack-priv abstract int toIndex(int pos)

Translates the logical position to physical index in the original source.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
unexpectedback to summary
pack-priv final void unexpected(String what)
withErrorSuppressedback to summary
pack-priv final boolean withErrorSuppressed(Parser<?> parser)

Runs parser with error recording suppressed.

org.jparsec back to summary

pack-priv final Enum ParseContext.ErrorType

extends Enum<ParseContext.ErrorType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ParseContext.ErrorType
DELIMITING

When the error is mostly lenient (as a delimiter of repetitions for example).

public static final ParseContext.ErrorType
EXPECTING

When Parser#label() is called.

public static final ParseContext.ErrorType
pack-priv final boolean
public static final ParseContext.ErrorType
MISSING

When any expected input isn't found.

public static final ParseContext.ErrorType
NONE

Default value, no error.

public static final ParseContext.ErrorType
UNEXPECTED

When Parser#not() is called.

Constructor Summary

AccessConstructor and Description
private
ErrorType(boolean mergeable)

Method Summary

Modifier and TypeMethod and Description
public static ParseContext.ErrorType
public static ParseContext.ErrorType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DELIMITINGback to summary
public static final ParseContext.ErrorType DELIMITING

When the error is mostly lenient (as a delimiter of repetitions for example).

EXPECTINGback to summary
public static final ParseContext.ErrorType EXPECTING

When Parser#label() is called. Signals that a logical stuff isn't found.

FAILUREback to summary
public static final ParseContext.ErrorType FAILURE

When Parsers#fail(String) is called. Signals a serious problem.

mergeableback to summary
pack-priv final boolean mergeable
MISSINGback to summary
public static final ParseContext.ErrorType MISSING

When any expected input isn't found.

NONEback to summary
public static final ParseContext.ErrorType NONE

Default value, no error.

UNEXPECTEDback to summary
public static final ParseContext.ErrorType UNEXPECTED

When Parser#not() is called. Signals that something isn't expected.

Constructor Detail

ErrorTypeback to summary
private ErrorType(boolean mergeable)

Method Detail

valueOfback to summary
public static ParseContext.ErrorType valueOf(String name)
valuesback to summary
public static ParseContext.ErrorType[] values()
org.jparsec back to summary

pack-priv Interface ParseContext.ParserTrace


Allows tracing of parsing progress during error condition, to ease debugging.

Method Summary

Modifier and TypeMethod and Description
public TreeNode
getCurrentNode()

Returns the current node, that is being parsed (not necessarily finished).

public TreeNode
getLatestChild()

Called by branching parsers, to save the current state of tree, before trying parsers that could modify the tree state.

public void
pop()

When a parser finishes, the current node is popped so we are back to the parent parser.

public void
push(String name)

Upon applying a parser with Parser#label, the label name is used to create a new child node under the current node.

public void
setCurrentResult(Object result)

Whenever a labeled parser succeeds, it calls this method to set its result in the trace.

public void
setLatestChild(TreeNode node)

Called by labeled parser to reset the current child node when the current node failed.

public void
setStateAs(ParseContext.ParserTrace that)

Set the enclosing parser's tree state into the nested parser's state.

public void
startFresh(ParseContext context)

Called when tokenizer passes on to token-level parser.

Method Detail

getCurrentNodeback to summary
public TreeNode getCurrentNode()

Returns the current node, that is being parsed (not necessarily finished).

getLatestChildback to summary
public TreeNode getLatestChild()

Called by branching parsers, to save the current state of tree, before trying parsers that could modify the tree state.

popback to summary
public void pop()

When a parser finishes, the current node is popped so we are back to the parent parser.

pushback to summary
public void push(String name)

Upon applying a parser with Parser#label, the label name is used to create a new child node under the current node. The new child node is set to be the current node.

setCurrentResultback to summary
public void setCurrentResult(Object result)

Whenever a labeled parser succeeds, it calls this method to set its result in the trace.

setLatestChildback to summary
public void setLatestChild(TreeNode node)

Called by labeled parser to reset the current child node when the current node failed. Also called by BestParser to set the optimum parse tree.

setStateAsback to summary
public void setStateAs(ParseContext.ParserTrace that)

Set the enclosing parser's tree state into the nested parser's state. Called for both nested token-level parser and nested scanner.

startFreshback to summary
public void startFresh(ParseContext context)

Called when tokenizer passes on to token-level parser.