public class Context extends AbstractFaAction
manages a context when running a DfaRun
. A context is the stretch of text between and
including the matches of a pair of regular expressions. To add the
two regular expressions to an Nfa
and associate
them with a Context
object, use a ContextManager
.
The Context
object allows for a client
action to be
run just before the context is entered and immediatly after the
context ends. Their default derives from the defaults set up in the
ContextManager
. They can be changed with setStartAction()
and setEndAction()
. Normally they are used to handle the text matching
the regular expressions defining the context.
The client actions may push/pop elements on/from the List
provided via the ContextStackProvider
that
must be available in DfaRun.clientData
field. Of
course the number of elements pushed and popped must match.
To define how the DfaRun
should handle unmatched
text within the context, call setFMB()
.
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getName()
returns the name of this
Context . |
void |
invoke(java.lang.StringBuilder yytext,
int start,
DfaRun r)
is called by methods of
DfaRun in case of a
match. |
Context |
setEndAction(FaAction a)
specifies the action which takes
care of the text marking the end of the context.
|
Context |
setFMB(DfaRun.FailedMatchBehaviour fmb)
specifies how the
DfaRun should handle
non-matching text within the context. |
Context |
setName(java.lang.String s)
sets the name of this object, which is currently only used to
have
toString() return something useful. |
Context |
setPopPriority(int p)
this method is not implemented and will always throw an
exception.
|
Context |
setStartAction(FaAction a)
specifies the action which shall take
care of the text marking the start of the context.
|
java.lang.String |
toString() |
mergeWith, setPriority
public Context setName(java.lang.String s)
sets the name of this object, which is currently only used to
have toString()
return something useful.
public java.lang.String getName()
returns the name of this Context
. If the name was
never set, this is null
.
setName(java.lang.String)
.public Context setStartAction(FaAction a)
specifies the action which shall take
care of the text marking the start of the context. The default
for this action is set up with ContextManager.setDefaultStartAction()
.
public Context setEndAction(FaAction a)
specifies the action which takes
care of the text marking the end of the context. The default
for this action is set up with ContextManager.setDefaultEndAction()
.
public Context setFMB(DfaRun.FailedMatchBehaviour fmb)
specifies how the DfaRun
should handle
non-matching text within the context.
public Context setPopPriority(int p)
this method is not implemented and will always throw an exception. It is only kept as a refence for the rare cases when someone thinks it is necessary to set the priority of the context pop action. This, however, can only be necessary if there is a conflict between matches within the context and the match terminating the context. While this is probably wrong anyway, it is still possible to give the action handling the in-context match a priority different from zero to make it different from the priority of the pop action.
java.lang.UnsupportedOperationException
- whenever called.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
public java.lang.String toString()
toString
in class java.lang.Object