Interface Context<V>
-
- All Known Implementing Classes:
MatcherContext
public interface Context<V>A Context object is available to parser actions methods during their runtime and provides various support functionalities.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanfastStringMatching()Returns true if fast string matching is enabled for this parsing run.chargetCurrentChar()Returns the character at the current index..intgetCurrentIndex()Returns the current index in the input buffer.chargetFirstMatchChar()Returns the first character of the input text matched by the rule immediately preceding the action expression that is currently being evaluated.InputBuffergetInputBuffer()Returns the InputBuffer the parser is currently running againstintgetLevel()Returns the current matcher level, with 0 being the root level, 1 being one level below the root and so on.java.lang.StringgetMatch()Returns the input text matched by the rule immediately preceding the action expression that is currently being evaluated.intgetMatchEndIndex()Returns the end index of the rule immediately preceding the action expression that is currently being evaluated.MatchergetMatcher()Returns the Matcher of this context or null, if this context is not valid anymore.intgetMatchLength()Returns the number of characters matched by the rule immediately preceding the action expression that is currently being evaluated.IndexRangegetMatchRange()Creates a newIndexRangeinstance covering the input text matched by the rule immediately preceding the action expression that is currently being evaluated.intgetMatchStartIndex()Returns the start index of the rule immediately preceding the action expression that is currently being evaluated.Context<V>getParent()Returns the parent context, i.e.java.util.List<ParseError>getParseErrors()Returns the list of parse errors for the entire parsing run.MatcherPathgetPath()Returns theMatcherPathto the currently running matcher.PositiongetPosition()Returns the current position in the underlyingInputBufferas aPositioninstance.intgetStartIndex()Returns the index into the underlying input buffer where the matcher of this context started its match.java.util.List<Node<V>>getSubNodes()Returns the parse tree subnodes already created in the current context scope.ValueStack<V>getValueStack()Returns the value stack instance used during this parsing run.booleanhasError()Determines if this context or any sub node recorded a parse error.booleaninErrorRecovery()Determines if the action calling this method is run during the resynchronization phase of an error recovery.booleaninPredicate()Determines if the current rule is running somewhere underneath a Test/TestNot rule.booleanisNodeSuppressed()Determines if the current context is for or below a rule marked @SuppressNode or below one marked @SuppressSubnodes.
-
-
-
Method Detail
-
getParent
Context<V> getParent()
Returns the parent context, i.e. the context for the currently running parent matcher.- Returns:
- the parent context
-
getInputBuffer
InputBuffer getInputBuffer()
Returns the InputBuffer the parser is currently running against- Returns:
- the InputBuffer
-
getMatcher
Matcher getMatcher()
Returns the Matcher of this context or null, if this context is not valid anymore.- Returns:
- the matcher
-
getStartIndex
int getStartIndex()
Returns the index into the underlying input buffer where the matcher of this context started its match.- Returns:
- the start index
-
getCurrentIndex
int getCurrentIndex()
Returns the current index in the input buffer.- Returns:
- the current index
-
getCurrentChar
char getCurrentChar()
Returns the character at the current index..- Returns:
- the current character
-
getParseErrors
java.util.List<ParseError> getParseErrors()
Returns the list of parse errors for the entire parsing run.- Returns:
- the list of parse errors
-
getPath
MatcherPath getPath()
Returns theMatcherPathto the currently running matcher.- Returns:
- the path
-
getLevel
int getLevel()
Returns the current matcher level, with 0 being the root level, 1 being one level below the root and so on.- Returns:
- the current matcher level
-
fastStringMatching
boolean fastStringMatching()
Returns true if fast string matching is enabled for this parsing run.
Fast string matching "short-circuits" the default practice of treating string rules as simple Sequence of character rules. When fast string matching is enabled strings are matched at once, without relying on inner CharacterMatchers. Even though this can lead to significant increases of parsing performance it does not play well with error reporting and recovery, which relies on character level matches. Therefore the
ReportingParseRunnerandRecoveringParseRunnerimplementations only enable fast string matching during their basic first parsing run and disable it once the input has proven to contain errors.- Returns:
- true if fast string matching is enabled during the current parsing run
-
getSubNodes
java.util.List<Node<V>> getSubNodes()
Returns the parse tree subnodes already created in the current context scope. Note that the returned list is immutable.- Returns:
- the parse tree subnodes already created in the current context scope
-
inPredicate
boolean inPredicate()
Determines if the current rule is running somewhere underneath a Test/TestNot rule.- Returns:
- true if the current context has a parent which corresponds to a Test/TestNot rule
-
inErrorRecovery
boolean inErrorRecovery()
Determines if the action calling this method is run during the resynchronization phase of an error recovery.- Returns:
- true if the action calling this method is run during the resynchronization phase of an error recovery
-
isNodeSuppressed
boolean isNodeSuppressed()
Determines if the current context is for or below a rule marked @SuppressNode or below one marked @SuppressSubnodes.- Returns:
- true or false
-
hasError
boolean hasError()
Determines if this context or any sub node recorded a parse error.- Returns:
- true if this context or any sub node recorded a parse error
-
getMatch
java.lang.String getMatch()
Returns the input text matched by the rule immediately preceding the action expression that is currently being evaluated. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.
- Returns:
- the input text matched by the immediately preceding subcontext
-
getFirstMatchChar
char getFirstMatchChar()
Returns the first character of the input text matched by the rule immediately preceding the action expression that is currently being evaluated. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.
If the immediately preceding rule did not match anything this method throws a GrammarException. If you need to able to handle that case use the getMatch() method.
- Returns:
- the input text matched by the immediately preceding subcontext
-
getMatchStartIndex
int getMatchStartIndex()
Returns the start index of the rule immediately preceding the action expression that is currently being evaluated. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.
- Returns:
- the start index of the context immediately preceding current action
-
getMatchEndIndex
int getMatchEndIndex()
Returns the end index of the rule immediately preceding the action expression that is currently being evaluated. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.
- Returns:
- the end index of the context immediately preceding current action, i.e. the index of the character immediately following the last matched character
-
getMatchLength
int getMatchLength()
Returns the number of characters matched by the rule immediately preceding the action expression that is currently being evaluated. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.
- Returns:
- the number of characters matched
-
getPosition
Position getPosition()
Returns the current position in the underlying
InputBufferas aPositioninstance.- Returns:
- the current position in the underlying inputbuffer
-
getMatchRange
IndexRange getMatchRange()
Creates a newIndexRangeinstance covering the input text matched by the rule immediately preceding the action expression that is currently being evaluated. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.- Returns:
- a new IndexRange instance
-
getValueStack
ValueStack<V> getValueStack()
Returns the value stack instance used during this parsing run.- Returns:
- the value stack
-
-