V
- the type of the parser valuespublic abstract class BaseActions<V> extends java.lang.Object implements ContextAware<V>
Constructor and Description |
---|
BaseActions() |
Modifier and Type | Method and Description |
---|---|
private void |
check() |
java.lang.Character |
currentChar()
Returns the next input character about to be matched.
|
int |
currentIndex()
Returns the current index in the input buffer.
|
boolean |
drop()
Removes the value at the top of the value stack.
|
boolean |
drop(int down)
Removes the value the given number of elements below the top of the value stack.
|
boolean |
dup()
Duplicates the top value of the value stack.
|
Context<V> |
getContext()
The current context for use with action methods.
|
boolean |
hasError()
Determines whether the current rule or a sub rule has recorded a parse error.
|
boolean |
inPredicate()
Returns true if the current rule is running somewhere underneath a Test/TestNot rule.
|
java.lang.String |
match()
Returns the input text matched by the rule immediately preceding the action expression that is currently
being evaluated.
|
char |
matchedChar()
Returns the first character of the input text matched by the rule immediately preceding the action
expression that is currently being evaluated.
|
int |
matchEnd()
Returns the end location of the rule immediately preceding the action expression that is currently
being evaluated.
|
int |
matchLength()
Returns the number of characters matched by the rule immediately preceding the action expression that is
currently being evaluated.
|
java.lang.String |
matchOrDefault(java.lang.String defaultString)
Returns the input text matched by the rule immediately preceding the action expression that is currently
being evaluated.
|
IndexRange |
matchRange()
Creates a new
IndexRange instance covering the input text matched by the rule immediately preceding the
action expression that is currently being evaluated. |
int |
matchStart()
Returns the start index of the rule immediately preceding the action expression that is currently
being evaluated.
|
boolean |
nodeSuppressed()
Returns true if the current context is for or below a rule marked @SuppressNode or below one
marked @SuppressSubnodes.
|
V |
peek()
Returns the value at the top of the value stack without removing it.
|
V |
peek(int down)
Returns the value the given number of elements below the top of the value stack without removing it.
|
boolean |
poke(int down,
V value)
Replaces the element the given number of elements below the current top of the value stack.
|
boolean |
poke(V value)
Replaces the current top value of the value stack with the given value.
|
V |
pop()
Removes the value at the top of the value stack and returns it.
|
V |
pop(int down)
Removes the value the given number of elements below the top of the value stack.
|
Position |
position()
Returns the current position in the underlying
InputBuffer as a
Position instance. |
boolean |
push(int down,
V value)
Inserts the given value a given number of elements below the current top of the value stack.
|
boolean |
push(V value)
Pushes the given value onto the value stack.
|
boolean |
pushAll(V firstValue,
V... moreValues)
Pushes all given elements onto the value stack (in the order as given).
|
void |
setContext(Context<V> context)
ContextAware interface implementation.
|
boolean |
swap()
Swaps the top two elements of the value stack.
|
boolean |
swap3()
Reverses the order of the top 3 value stack elements.
|
boolean |
swap4()
Reverses the order of the top 4 value stack elements.
|
boolean |
swap5()
Reverses the order of the top 5 value stack elements.
|
boolean |
swap6()
Reverses the order of the top 6 value stack elements.
|
public Context<V> getContext()
public void setContext(Context<V> context)
setContext
in interface ContextAware<V>
context
- the contextpublic int currentIndex()
public java.lang.String match()
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.
public IndexRange matchRange()
IndexRange
instance 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.public java.lang.String matchOrDefault(java.lang.String defaultString)
Returns the input text matched by the rule immediately preceding the action expression that is currently being evaluated. If the matched input text is empty the given default string is returned. This call can only be used in actions that are part of a Sequence rule and are not at first position in this Sequence.
defaultString
- the default string to return if the matched input text is emptypublic char matchedChar()
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.
public int matchStart()
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.
public int matchEnd()
Returns the end location 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.
public int matchLength()
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.
public Position position()
Returns the current position in the underlying InputBuffer
as a
Position
instance.
public boolean push(V value)
value
- the value to pushpublic boolean push(int down, V value)
down
- the number of elements to skip before inserting the value (0 being equivalent to push(value))value
- the valuejava.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationpublic boolean pushAll(V firstValue, V... moreValues)
firstValue
- the first valuemoreValues
- the other valuespublic V pop()
java.lang.IllegalArgumentException
- if the stack is emptypublic V pop(int down)
down
- the number of elements to skip before removing the value (0 being equivalent to pop())java.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationpublic boolean drop()
java.lang.IllegalArgumentException
- if the stack is emptypublic boolean drop(int down)
down
- the number of elements to skip before removing the value (0 being equivalent to drop())java.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationpublic V peek()
java.lang.IllegalArgumentException
- if the stack is emptypublic V peek(int down)
down
- the number of elements to skip (0 being equivalent to peek())java.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationpublic boolean poke(V value)
value
- the valuejava.lang.IllegalArgumentException
- if the stack is emptypublic boolean poke(int down, V value)
down
- the number of elements to skip before replacing the value (0 being equivalent to poke(value))value
- the value to replace withjava.lang.IllegalArgumentException
- if the stack does not contain enough elements to perform this operationpublic boolean dup()
java.lang.IllegalArgumentException
- if the stack is emptypublic boolean swap()
GrammarException
- if the stack does not contain at least two elementspublic boolean swap3()
GrammarException
- if the stack does not contain at least 3 elementspublic boolean swap4()
GrammarException
- if the stack does not contain at least 4 elementspublic boolean swap5()
GrammarException
- if the stack does not contain at least 5 elementspublic boolean swap6()
GrammarException
- if the stack does not contain at least 6 elementspublic java.lang.Character currentChar()
public boolean inPredicate()
return Sequence(
...,
inPredicate() || actions.doSomething()
);
public boolean nodeSuppressed()
public boolean hasError()
return Sequence(
...,
!hasError() && actions.doSomething()
);
private void check()