T
- the type wrapped by this Varpublic class Var<T> extends Reference<T>
This class provides a "local variable"-like construct for action expressions in parser rule methods.
Var objects wrap an internal value of an arbitrary (reference) type, can have an initial value, allow read/write access to their values and can be passed around as parameters to nested rule methods.
Each rule invocation (i.e. rule matching attempt) receives its own scope (which is automatically initialized with the initial value), so actions in recursive rules work just like expected.
Var objects generally behave just like local variables with one exception:
When rule method rule1()
passes a Var defined in its scope to another
rule method rule2()
as a parameter, and an action in rule method
rule2()
writes to this Var, all actions in rule method rule1()
running after rule2()
will "see" this newly written value
(since values in Var objects are passed by reference).
Constructor and Description |
---|
Var()
Initializes a new Var with a null initial value.
|
Var(Supplier<T> supplier)
Initializes a new Var.
|
Var(T value)
Initializes a new Var with the given initial value.
|
Modifier and Type | Method and Description |
---|---|
boolean |
enterFrame()
Provides a new frame for the variable.
|
boolean |
exitFrame()
Exits a frame previously entered with
enterFrame() . |
int |
getLevel()
Returns the current frame level of this variable, the very first level
corresponding to zero.
|
String |
getName()
Gets the name of this Var.
|
void |
setName(String name)
Sets the name of this Var.
|
String |
toString() |
public Var()
public Var(@Nullable T value)
value
- the valuepublic final String getName()
public final void setName(String name)
name
- the namepublic final int getLevel()
public final boolean enterFrame()
Do not use manually!
public final boolean exitFrame()
enterFrame()
.
Do not use manually!