public class Hold extends AbstractFaAction
hold back output until a decision can be made whether to ship or to drop filtered output. Associate this callback with a pattern that defines the start of a lengthy region of text only at the end of which a decision can be made whether to drop it or copy it to the output.
This callback sets DfaRun.collect
to
true
and records the position. To store the position,
the callback obtains a Map
from a MapProvider
that has to be in the DfaRun.clientData
field of
the calling DfaRun
. The Hold
object
stores only one entry in the Map
with itself as the
key. Consequently you may use the Map
in other
callbacks to store information that may be necessary to make the
later decision whether to ship or drop the text.
At the point where the decision can be made, use the callback
generated by either drop()
or ship()
to
delete or deliver the output held back so far. A typical use looks
like:
Hold hold = new Hold(); ... nfa.or("start", hold) .or("goodEnd", hold.ship()) .or("badEnd", hold.drop()) // or in a different scenario with If .or("end", new If(v, hold.ship(), hold.drop()))
In the use with If
, v
would be a Verifier
which performs whatever test is necessary to check
whether the held back output shall be shipped or dropped.
Objects of this class can operate in nested contexts. Only the
outermost Hold
object will set DfaRun.collect
back to false.
Constructor and Description |
---|
Hold() |
Modifier and Type | Method and Description |
---|---|
AbstractFaAction |
drop()
create an
FaAction which drops (deletes) the
output
held back by this object. |
int |
getStart(DfaRun r)
returns the position this object current refers to as the start
position where data is being hold back.
|
void |
invoke(java.lang.StringBuilder yytext,
int start,
DfaRun r)
is called by methods of
DfaRun in case of a
match. |
AbstractFaAction |
ship()
create an
FaAction which ships (delivers) the
output
held back by this object. |
mergeWith, setPriority
public void invoke(java.lang.StringBuilder yytext, int start, DfaRun r)
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
.
public int getStart(DfaRun r)
returns the position this object current refers to as the start position where data is being hold back.
public AbstractFaAction drop()
create an FaAction
which drops (deletes) the
output
held back by this object. The action returned
will throw an IllegalStateException
when called
while there is no data being held back.
public AbstractFaAction ship()
create an FaAction
which ships (delivers) the
output
held back by this object. The action returned
will throw an IllegalStateException
when called
while there is no data being is held back.