public class If extends AbstractFaAction
run one or another FaAction
depending on the outcome
of asking a Verifier
. A typical use case normally employs
a Verifier
and a Hold
:
Hold hold = new Hold(); Count c = new Count("yada"); Nfa nfa = new Nfa("start", new Run(hold, c.reset())) .or("cute pattern", c) .or("end", new If(c.ge(2), hold.ship(), hold.drop());
In the example, a Count
object is used to count the
occurrences of the string "cute pattern"
. The counter
is reset on seeing "start"
. When seeing
"end"
, If
calls the Verifier
returned by c.ge(2)
which will return
true
or false
depending on whether more
than 1 pattern was seen. Then it calls one of the actions
hold.ship()
or hold.drop()
accordingly.
Constructor and Description |
---|
If(Verifier v,
FaAction thendo,
FaAction elsedo) |
Modifier and Type | Method and Description |
---|---|
void |
invoke(java.lang.StringBuilder yytext,
int start,
DfaRun r)
is called by methods of
DfaRun in case of a
match. |
mergeWith, setPriority
public void invoke(java.lang.StringBuilder yytext, int start, DfaRun r) throws CallbackException
FaAction
is called by methods of DfaRun
in case of a
match. Parameter yytext
contains the matching text
from position start
onwards. The callback may change
the whole of yytext
, but the under most
circumstances, only the matching text should be
changed. Parameter runner
is the DfaRun
object which called this function. Of interest are its fields
DfaRun.clientData
and DfaRun.collect
.
CallbackException