public class ContextManager
extends java.lang.Object
populates a Nfa
with regex/action pairs
which keep track of nested matching contexts. Objects of this class
are expected to be used as follows:
Nfa
to
populate.setDefault...
methods.Nfa
with any of the
add...()
methods.Nfa
,
typically with calls like.or("regex", new IfContext().ifthen(ctx, action))where
ctx
is a context returned by a one of the
add...()
methods.
Note that changing the defaults on this object will have effect
only for subsequent add...()
calls.
Modifier and Type | Field and Description |
---|---|
static Context |
anyContext |
Constructor and Description |
---|
ContextManager(Nfa nfa)
creates an object to populate the given
Nfa with
regex/action pairs for context matching. |
Modifier and Type | Method and Description |
---|---|
Context |
add(Context parent,
java.lang.String reIn,
java.lang.String reOut)
adds a new context to the client
Nfa . |
Context |
add(java.lang.String reIn,
java.lang.String reOut)
calls
add(Context,String,String) such that the
context is entered in any parent context. |
Context |
addXml()
calls
add(Context,String,String) such that
reIn and reOut match the start and end
of any XML element. |
Context |
addXml(Context parent,
java.lang.String tagname)
calls
add(parent,reIn,reOut) such that reIn and
reOut match the start and end of the XML element
with the given tagname . |
Context[] |
addXml(Context parent,
java.lang.String[] tagnames)
creates a nested hierarchy of contexts defined by the XML
tagnames given.
|
Context |
addXml(java.lang.String tagname)
calls
add(Context,String,String)
such that reIn and reOut match the
start and end of the XML element with the given
tagname . |
static java.lang.Object |
createStackProvider()
is a convenience method to create a sufficient implementation
of a
ContextStackProvider . |
static java.lang.Object |
pop(java.util.List<java.lang.Object> stack)
is a convenience method to help client actions to operate the
List provided by the ContextStackProvider
via DfaRun.clientData as a stack. |
ContextManager |
setDefaultAction(FaAction a)
calls both,
setDefaultStartAction()
and setDefaultEndAction() with the
given action. |
ContextManager |
setDefaultEndAction(FaAction a)
defines the default action to be applied to the text matching
a context end.
|
ContextManager |
setDefaultFMB(DfaRun.FailedMatchBehaviour fmb)
defines the default behaviour into which the
DfaRun is switched, when a context is entered. |
ContextManager |
setDefaultStartAction(FaAction a)
defines the default action to be applied to the text matching
a context start.
|
public static final Context anyContext
public ContextManager(Nfa nfa)
creates an object to populate the given Nfa
with
regex/action pairs for context matching.
public ContextManager setDefaultFMB(DfaRun.FailedMatchBehaviour fmb)
defines the default behaviour into which the DfaRun
is switched, when a context is entered. It
defines how unmatched stretches of input shall be handled within
the context. The default can be changed for individual Context
objects with their setFMB()
method.
public ContextManager setDefaultStartAction(FaAction a)
defines the default action to be applied to the text matching
a context start. The default can be changed for
individual Context
objects with their setStartAction()
method. If this method is never
called or is called with null
, the context start
text is copied to the output unchanged.
setDefaultAction(monq.jfa.FaAction)
public ContextManager setDefaultEndAction(FaAction a)
defines the default action to be applied to the text matching
a context end. The comments to setDefaultStartAction()
apply.
setDefaultAction(monq.jfa.FaAction)
public ContextManager setDefaultAction(FaAction a)
calls both, setDefaultStartAction()
and setDefaultEndAction()
with the
given action.
public Context add(Context parent, java.lang.String reIn, java.lang.String reOut) throws ReSyntaxException
adds a new context to the client Nfa
. The context
starts whenever the regular expression reIn
matches while the given parent
context is active. It
ends as soon as reOut
is found.
With parent==null
, reIn
will only
switch to the new context from the outermost level, i.e. when no
context was yet entered. Note that this is in line with IfContext()
when called with
null
. If you want to match reIn
to
always match, independent of context, then use add(String,String)
.
The defaults of the context returned will be be initialized
from the defaults stored in this
with any of the
setDefault...
methods. They can be changed on the
object returned as needed.
parent
- may be null to denote the outermost level.reIn
- is the regular expression denoting the start of the
new context being added to the client Nfa
reOut
- is the regular expression denoting the end of the
new context being added to the client Nfa
Nfa
. You need the returned object to change its
default behaviour and as a parent parameter for further calls to
this method. Do not add the resulting context to any
Nfa
.ReSyntaxException
public Context add(java.lang.String reIn, java.lang.String reOut) throws ReSyntaxException
calls add(Context,String,String)
such that the
context is entered in any parent context.
ReSyntaxException
public Context addXml(Context parent, java.lang.String tagname) throws ReSyntaxException
calls add(parent,reIn,reOut)
such that reIn
and
reOut
match the start and end of the XML element
with the given tagname
.
For the use of null
as a parent, see add(Context,String,String)
.
ReSyntaxException
public Context addXml(java.lang.String tagname) throws ReSyntaxException
calls add(Context,String,String)
such that reIn
and reOut
match the
start and end of the XML element with the given
tagname
.
ReSyntaxException
public Context[] addXml(Context parent, java.lang.String[] tagnames) throws ReSyntaxException
creates a nested hierarchy of contexts defined by the XML
tagnames given. The parent context for the element with tagname
tagnames[0]
will be the given
parent
. The context for further elements is always
the previous context in the list.
parent
- may be null
.ReSyntaxException
public Context addXml() throws ReSyntaxException
calls add(Context,String,String)
such that
reIn
and reOut
match the start and end
of any XML element.
ReSyntaxException
public static java.lang.Object pop(java.util.List<java.lang.Object> stack)
is a convenience method to help client actions to operate the
List
provided by the ContextStackProvider
via DfaRun.clientData
as a stack.
A push method is not provided because it would be a only an
alias for
List.add()
.
public static java.lang.Object createStackProvider()
is a convenience method to create a sufficient implementation
of a ContextStackProvider
.