V
- the type of the parser valuespublic abstract class BaseActions<V> extends Object implements ContextAware<V>
Constructor and Description |
---|
BaseActions() |
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
String |
matchOrDefault(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.
|
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.
|
<E extends V> |
peekAs(Class<E> c)
Returns and casts the value at the top of the value stack without
removing it.
|
<E extends V> |
peekAs(Class<E> c,
int down)
Returns and casts 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 and returns it
|
<E extends V> |
popAs(Class<E> c)
Removes the value at the top of the value stack and casts it before
returning it
|
<E extends V> |
popAs(Class<E> c,
int down)
Removes the value the given number of elements below the top of the value
stack and casts it before returning it
|
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.
|
void |
setContext(Context<V> context)
ContextAware interface implementation.
|
boolean |
swap()
Swaps the top two elements of the value stack.
|
boolean |
swap(int n)
Reverse the order of the top n elements of this context's value stack
|
public final Context<V> getContext()
public final void setContext(Context<V> context)
setContext
in interface ContextAware<V>
context
- the contextpublic final int currentIndex()
public 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 String matchOrDefault(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 be 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 valueIllegalArgumentException
- if the stack does not contain enough
elements to perform this operationpublic V pop()
IllegalArgumentException
- if the stack is emptypublic <E extends V> E popAs(@Nonnull Class<E> c)
E
- type of the classc
- the class to cast toIllegalArgumentException
- if the stack is emptypop()
public V pop(int down)
down
- the number of elements to skip before removing the value (0
being equivalent to pop())IllegalArgumentException
- if the stack does not contain enough
elements to perform this operationpublic <E extends V> E popAs(Class<E> c, int down)
E
- type of the classc
- the class to cast todown
- the number of elements to skip before removing the value (0
being equivalent to pop())IllegalArgumentException
- if the stack does not contain enough
elements to perform this operationpop(int)
public boolean drop()
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())IllegalArgumentException
- if the stack does not contain enough
elements to perform this operationpublic V peek()
IllegalArgumentException
- if the stack is emptypublic <E extends V> E peekAs(Class<E> c)
E
- type of the classc
- the class to cast topeek()
public V peek(int down)
down
- the number of elements to skip (0 being equivalent to peek())IllegalArgumentException
- if the stack does not contain enough
elements to perform this operationpublic <E extends V> E peekAs(Class<E> c, int down)
E
- type of the classc
- the class to cast todown
- the number of elements to skip (0 being equivalent to peek())peek(int)
public boolean poke(V value)
value
- the valueIllegalArgumentException
- 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 withIllegalArgumentException
- if the stack does not contain enough
elements to perform this operationpublic boolean dup()
IllegalArgumentException
- if the stack is emptypublic boolean swap()
IllegalArgumentException
- if the stack does not contain at least
two elementspublic boolean swap(int n)
n
- the number of elements to swapIllegalArgumentException
- stack does not contain enough elementsValueStack.swap(int)
public Character currentChar()
public boolean inPredicate()
return Sequence(
...,
inPredicate() || actions.doSomething()
);
public boolean hasError()
return Sequence(
...,
!hasError() && actions.doSomething()
);