public class CalcASTPropsVisitor extends DepthFirstTraversalRegexASTVisitor
RegexAST and its RegexASTNodes, in
two passes.
RegexASTNode.getMinPath():
BackReference, PositionAssertion, LookBehindAssertion
and LookAheadAssertion nodes is the minimum number of CharacterClass nodes that need to
be traversed in order to reach the node.MatchFound nodes is undefined (or is always 0). Their minPath is never
set by CalcASTPropsVisitor.Sequence and Group nodes is the minimum number of
CharacterClass nodes that need to be traversed (starting at the AST root) 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 CalcASTPropsVisitor.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.
LookAroundAssertions are treated separately, so their minPath values
have nothing to do with their parent expression.RegexASTNode.getMaxPath() is set analogous to RegexASTNode.getMinPath(), but
without taking loops (Group.isLoop()) into account.RegexASTNode.isDead(): The following nodes are marked as dead:
PositionAssertions whose minimum path is greater than zero (type
PositionAssertion.Type.CARET in forward mode
and PositionAssertion.Type.DOLLAR in backward
mode). 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.CharacterClasses that don't match anything (SortedListOfRanges.matchesNothing()).
Sequences that contain a dead node.Groups where all alternatives are dead.RegexASTSubtreeRootNodes whose child group is dead.RegexASTNode.startsWithCaret()/RegexASTNode.endsWithDollar():
Sequences that start with a caret PositionAssertion / end with a dollar
PositionAssertion.Groups where all alternatives start with a caret / end with a dollar.RegexASTNode.hasCaret()/RegexASTNode.hasDollar():
Sequences that contain a caret / dollar PositionAssertion.Groups where any alternatives contains a caret / dollar PositionAssertion.
RegexAST.getReachableCarets()/RegexAST.getReachableDollars(): all
caret/dollar PositionAssertion that are not dead are added to these lists.RegexAST.getLookArounds()}: all reachable LookAroundAssertions are added to
these lists.RegexAST.getReachableCarets(),
RegexAST.getReachableDollars(),
RegexAST.getLookArounds(),
RegexASTNode.hasCaret(),
RegexASTNode.hasDollar(),
RegexASTNode.startsWithCaret(),
RegexASTNode.endsWithDollar(),
RegexASTNode.getMinPath(),
RegexASTNode.getMaxPath(),
RegexASTNode.isDead(),
RegexAST.createPrefix()| Constructor and Description |
|---|
CalcASTPropsVisitor(RegexAST ast) |
| 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) |
static void |
run(RegexAST ast) |
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(PositionAssertion assertion) |
protected void |
visit(Sequence sequence) |
isForward, isReverse, leave, run, runReversedoLeave, doVisitpublic CalcASTPropsVisitor(RegexAST ast)
public static void run(RegexAST ast)
protected 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 DepthFirstTraversalRegexASTVisitor