Class CalcASTPropsVisitor
java.lang.Object
com.oracle.truffle.regex.tregex.parser.ast.visitors.RegexASTVisitor
com.oracle.truffle.regex.tregex.parser.ast.visitors.DepthFirstTraversalRegexASTVisitor
com.oracle.truffle.regex.tregex.parser.ast.CalcASTPropsVisitor
This visitor computes various properties of
RegexAST and its RegexASTNodes, in
two passes.
RegexASTNode.getMinPath():- The minPath of
BackReference,PositionAssertion,LookBehindAssertionandLookAheadAssertionnodes is the minimum number of CharacterClass nodes that need to be traversed in order to reach the node. - The minPath of
MatchFoundnodes is undefined (or is always 0). Their minPath is never set byCalcASTPropsVisitor. - The minPath of
SequenceandGroupnodes is the minimum number ofCharacterClassnodes that need to be traversed (starting at the AST root) in order to reach the end of the node. The minPath field ofSequencenodes is used as a mutable iteration variable when traversing their children (seevisit(CharacterClass)). The resulting value after the traversal holds the minimum number ofCharacterClassnodes that need to be traversed to reach the end of the Sequence. The same holds forGroupnodes. - The contents of
LookAroundAssertions are treated separately, so their minPath values have nothing to do with their parent expression.
- The minPath of
RegexASTNode.getMaxPath()is set analogous toRegexASTNode.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 (typePositionAssertion.Type.CARETin forward mode andPositionAssertion.Type.DOLLARin 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 caretPositionAssertion/ end with a dollarPositionAssertion.Groups where all alternatives start with a caret / end with a dollar.
RegexASTNode.hasCaret()/RegexASTNode.hasDollar():Sequences that contain a caret / dollarPositionAssertion.Groups where any alternatives contains a caret / dollarPositionAssertion.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidinit(RegexASTNode runRoot) protected voidleave(AtomicGroup atomicGroup) protected voidprotected voidleave(LookAheadAssertion assertion) protected voidleave(LookBehindAssertion assertion) protected voidstatic voidrun(RegexAST ast, CompilationBuffer compilationBuffer) protected voidvisit(AtomicGroup atomicGroup) protected voidvisit(BackReference backReference) protected voidvisit(CharacterClass characterClass) protected voidprotected voidvisit(LookAheadAssertion assertion) protected voidvisit(LookBehindAssertion assertion) protected voidvisit(PositionAssertion assertion) protected voidprotected voidvisit(SubexpressionCall subexpressionCall) Methods inherited from class com.oracle.truffle.regex.tregex.parser.ast.visitors.DepthFirstTraversalRegexASTVisitor
done, isForward, isReverse, run, runReverseMethods inherited from class com.oracle.truffle.regex.tregex.parser.ast.visitors.RegexASTVisitor
doLeave, doVisit
-
Constructor Details
-
CalcASTPropsVisitor
-
-
Method Details
-
run
-
init
- Overrides:
initin classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
leave
- Overrides:
leavein classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
leave
- Overrides:
leavein classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
leave
- Overrides:
leavein classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
leave
- Overrides:
leavein classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
leave
- Overrides:
leavein classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-
visit
- Overrides:
visitin classDepthFirstTraversalRegexASTVisitor
-