public class CalcMinPathsVisitor extends DepthFirstTraversalRegexASTVisitor
RegexASTNode.getMinPath() - property of children of an AST in
the following manner:
LookBehindAssertion and LookAheadAssertion nodes is the
minimum number of CharacterClass nodes that need to be traversed in order to reach the node.BackReference, PositionAssertion and MatchFound nodes
is undefined (or is always 0). Their minPath is never set by CalcMinPathsVisitor.Sequence and Group nodes is the minimum number of
CharacterClass nodes that need to be traversed in order to reach the end of the node. The
minPath field of Sequence nodes is used as a mutable iteration variable when traversing
their children (see CalcMinPathsVisitor.visit(CharacterClass)). The resulting value after the traversal
holds the minimum number of CharacterClass nodes that need to be traversed to reach the
end of the Sequence. The same holds for Group nodes.CalcMinPathsVisitor will also set RegexASTNode.getMaxPath(), analogous to
RegexASTNode.getMinPath(), but without taking loops (Group.isLoop()) into
account. CalcMinPathsVisitor will simultaneously mark PositionAssertions (type
PositionAssertion.Type.CARET in forward mode
and PositionAssertion.Type.DOLLAR in backward
mode) whose minimum path is greater than zero as dead. Note that this algorithm will e.g. not
mark the dollar assertion in /(?=a$)bc/ as dead, since it has a (reverse) minimum path of
0 inside the look-ahead assertion. The visitor will also mark all Sequence nodes that
start with a caret PositionAssertion or end with a dollar PositionAssertion with
the RegexASTNode.startsWithCaret()/RegexASTNode.endsWithDollar() flags, and
likewise for all Groups where all child Sequences start with a caret or end with
a dollar. The visitor is intended to be run on an AST once in reverse, and then once in forward
direction. The results of the forward run will be used by RegexAST.createPrefix().| Constructor and Description |
|---|
CalcMinPathsVisitor() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
init(RegexASTNode runRoot) |
protected void |
leave(Group group) |
protected void |
leave(LookAheadAssertion assertion) |
protected void |
leave(LookBehindAssertion assertion) |
void |
leaveLookAroundAssertion(LookAroundAssertion assertion) |
protected void |
visit(BackReference backReference) |
protected void |
visit(CharacterClass characterClass) |
protected void |
visit(Group group) |
protected void |
visit(LookAheadAssertion assertion) |
protected void |
visit(LookBehindAssertion assertion) |
protected void |
visit(MatchFound matchFound) |
protected void |
visit(PositionAssertion assertion) |
protected void |
visit(Sequence sequence) |
isReverse, leave, run, runReversedoLeave, doVisitprotected void init(RegexASTNode runRoot)
init in class DepthFirstTraversalRegexASTVisitorprotected void visit(BackReference backReference)
visit in class DepthFirstTraversalRegexASTVisitorprotected void visit(Group group)
visit in class DepthFirstTraversalRegexASTVisitorprotected void leave(Group group)
leave in class DepthFirstTraversalRegexASTVisitorprotected void visit(Sequence sequence)
visit in class DepthFirstTraversalRegexASTVisitorprotected void visit(PositionAssertion assertion)
visit in class DepthFirstTraversalRegexASTVisitorprotected void visit(LookBehindAssertion assertion)
visit in class DepthFirstTraversalRegexASTVisitorprotected void leave(LookBehindAssertion assertion)
leave in class DepthFirstTraversalRegexASTVisitorprotected void visit(LookAheadAssertion assertion)
visit in class DepthFirstTraversalRegexASTVisitorprotected void leave(LookAheadAssertion assertion)
leave in class DepthFirstTraversalRegexASTVisitorpublic void leaveLookAroundAssertion(LookAroundAssertion assertion)
protected void visit(CharacterClass characterClass)
visit in class DepthFirstTraversalRegexASTVisitorprotected void visit(MatchFound matchFound)
visit in class DepthFirstTraversalRegexASTVisitor