Class Group
- All Implemented Interfaces:
AbstractState<Term,,ASTTransition> RegexASTVisitorIterable,JsonConvertible
- Direct Known Subclasses:
ConditionalBackReferenceGroup
A Group is composed of several alternatives, each of which is a Sequence of other
Terms. A Group can be wrapped in parentheses and used anywhere a Term is
expected. Therefore, Group extends Term.
Corresponds to the goal symbol Disjunction and the right-hand sides ( Disjunction ) and ( ? : Disjunction ) of the goal symbol Atom in the ECMAScript RegExp syntax.
On top of managing alternation and capturing, the Group AST nodes are also the primitives
used to represent loops (quantifiers * and +). A Group can be marked as looping, in which
case successfully matching one of its non-empty alternatives should be followed by attempting to
match the Group itself again.
The collections of alternatives that make up a Group is ordered and the order indicates
the priority of the alternatives: if matching with an earlier alternative is possible, that match
result is preferred to those from later alternatives.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new alternative to this group.addSequence(RegexAST ast) Creates a new empty alternatives and adds it to the end of the list of alternatives.voidMarks thisGroupas non-capturing and clears its group number.Copy this node only, without any child nodes.copyRecursive(RegexAST ast, CompilationBuffer compilationBuffer) Recursively copy this subtree.booleanequalsSemantic(RegexASTNode obj, boolean ignoreQuantifier) Returns the list of alternatives that make up thisGroup.intReturns the index corresponding to this capture group's END in a result array returned by a capture-group aware DFA.intReturns the index corresponding to this capture group's BEGIN in a result array returned by a capture-group aware DFA.intGets the (exclusive) upper bound of the range of capture groups in this term.intGets the (inclusive) lower bound of the range of capture groups in this term.intGets the (exclusive) upper bound of the range of capture groups contained within this group.intGets the (inclusive) lower bound of the range of capture groups contained within this group.intReturns the number of this capturing group.intstatic intgroupNumberToBoundaryIndexEnd(int groupNumber) Returns the index corresponding to a capture group's END in a result array returned by a capture-group aware DFA.static intgroupNumberToBoundaryIndexStart(int groupNumber) Returns the index corresponding to a capture group's BEGIN in a result array returned by a capture-group aware DFA.booleanbooleanvoidinsertFirst(Sequence sequence) Inserts a new alternative to this group.booleanReturnstrueiff all alternatives of this group match only the empty string.booleanReturns whether this group is a capturing group.booleanisEmpty()booleanbooleanReturns whether this group declares local flags, e.g.booleanisLoop()Returns whether this group loops.booleanReturnstrueiff the parser should try to unroll this term's quantifier.voidvoidvoidsetAlternatives(ArrayList<Sequence> alternatives) voidsetEnclosedCaptureGroupsHigh(int enclosedCaptureGroupsHigh) Sets the (exclusive) upper bound of the range of capture groups contained within this group.voidsetEnclosedCaptureGroupsLow(int enclosedCaptureGroupsLow) Sets the (inclusive) lower bound of the range of capture groups contained within this group.voidsetGroupNumber(int groupNumber) Marks thisGroupas capturing and sets its group number.voidsetGroupsWithGuardsIndex(int groupsWithGuardsIndex) voidsetLocalFlags(boolean loop) Sets whether this group declares local flags, e.g.voidsetLoop(boolean loop) Sets whether this group should loop.intsize()toJson()toString()visitorGetNext(boolean reverse) booleanMethods inherited from class com.oracle.truffle.regex.tregex.parser.ast.QuantifiableTerm
equalsSemantic, getQuantifier, getSubTreeParent, hasNotUnrolledQuantifier, hasQuantifier, quantifierToString, setQuantifierMethods inherited from class com.oracle.truffle.regex.tregex.parser.ast.Term
getSeqIndex, setSeqIndexMethods inherited from class com.oracle.truffle.regex.tregex.parser.ast.RegexASTNode
asAtomicGroup, asBackReference, asCharacterClass, asConditionalBackReferenceGroup, asGroup, asLookAheadAssertion, asLookAroundAssertion, asLookBehindAssertion, asMatchFound, asPositionAssertion, asQuantifiableTerm, asSequence, asSubexpressionCall, asSubtreeRootNode, astNodeId, endsWithDollar, getFlags, getId, getMaxPath, getMinPath, getParent, getPrefixLengthMax, getPrefixLengthMin, hasBackReferences, hasCaptureGroups, hasCaret, hasDollar, hasEmptyGuard, hasLookAheads, hasLookBehinds, hasLoops, hasQuantifiers, hasVariablePrefixLength, idInitialized, incMaxPath, incMaxPath, incMinPath, incMinPath, isAtomicGroup, isBackReference, isCaret, isCharacterClass, isConditionalBackReferenceGroup, isDead, isDollar, isExpandedQuantifier, isFlagSet, isGroup, isGroupWithGuards, isInLookAheadAssertion, isInLookBehindAssertion, isLookAheadAssertion, isLookAroundAssertion, isLookBehindAssertion, isMandatoryUnrolledQuantifier, isMatchFound, isPositionAssertion, isPrefix, isQuantifiableTerm, isQuantifierPassThroughSequence, isRoot, isSequence, isSubexpressionCall, isSubtreeRoot, markAsDead, setDead, setEmptyGuard, setEndsWithDollar, setEndsWithDollar, setExpandedQuantifier, setFlag, setFlag, setFlags, setHasBackReferences, setHasCaptureGroups, setHasCaret, setHasCaret, setHasDollar, setHasDollar, setHasLookAheads, setHasLookBehinds, setHasLoops, setHasLoops, setHasQuantifiers, setId, setMandatoryUnrolledQuantifier, setMaxPath, setMinPath, setParent, setPrefix, setPrefixLengthMax, setPrefixLengthMin, setQuantifierPassThroughSequence, setStartsWithCaret, setStartsWithCaret, startsWithCaret, toJson, toStringWithIDMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.oracle.truffle.regex.tregex.automaton.AbstractState
getId
-
Constructor Details
-
Group
-
-
Method Details
-
copy
Description copied from class:RegexASTNodeCopy this node only, without any child nodes. The ID and minPath of the copied nodes is left unset.- Specified by:
copyin classQuantifiableTerm- Parameters:
ast- RegexAST the node should belong to.- Returns:
- A shallow copy of this node.
-
copyRecursive
Description copied from class:RegexASTNodeRecursively copy this subtree. This method should be used instead ofCopyVisitorif the copying process is required to be thread-safe. The ID and minPath of the copied nodes is left unset.- Specified by:
copyRecursivein classTerm- Parameters:
ast- RegexAST the new nodes should belong to.- Returns:
- A deep copy of this node.
-
isLoop
public boolean isLoop()Returns whether this group loops. A looping group differs from a non-looping one in that when you match one of the group's non-empty alternatives, instead of continuing to the next node after the group, the same group is attempted again. -
setLoop
public void setLoop(boolean loop) Sets whether this group should loop. If the group is set to be looping, this updates the 'next' and 'prev' pointers on the non-empty alternatives to point to the group itself.- Parameters:
loop- true if this group should loop- See Also:
-
isLocalFlags
public boolean isLocalFlags()Returns whether this group declares local flags, e.g. "(?i:...)". -
setLocalFlags
public void setLocalFlags(boolean loop) Sets whether this group declares local flags, e.g. "(?i:...)".- See Also:
-
getGroupNumber
public int getGroupNumber()Returns the number of this capturing group. If this group is not a capturing group, returns -1. -
getBoundaryIndexStart
public int getBoundaryIndexStart()Returns the index corresponding to this capture group's BEGIN in a result array returned by a capture-group aware DFA. -
getBoundaryIndexEnd
public int getBoundaryIndexEnd()Returns the index corresponding to this capture group's END in a result array returned by a capture-group aware DFA. -
groupNumberToBoundaryIndexStart
public static int groupNumberToBoundaryIndexStart(int groupNumber) Returns the index corresponding to a capture group's BEGIN in a result array returned by a capture-group aware DFA. -
groupNumberToBoundaryIndexEnd
public static int groupNumberToBoundaryIndexEnd(int groupNumber) Returns the index corresponding to a capture group's END in a result array returned by a capture-group aware DFA. -
isCapturing
public boolean isCapturing()Returns whether this group is a capturing group.This is the case when this Group was built using the
Group(int)constructor or ifsetGroupNumber(int)was called. -
setGroupNumber
public void setGroupNumber(int groupNumber) Marks thisGroupas capturing and sets its group number.- Parameters:
groupNumber-
-
hasGroupWithGuardsIndex
public boolean hasGroupWithGuardsIndex() -
getGroupsWithGuardsIndex
public int getGroupsWithGuardsIndex() -
setGroupsWithGuardsIndex
public void setGroupsWithGuardsIndex(int groupsWithGuardsIndex) -
clearGroupNumber
public void clearGroupNumber()Marks thisGroupas non-capturing and clears its group number. -
getEnclosedCaptureGroupsLow
public int getEnclosedCaptureGroupsLow()Gets the (inclusive) lower bound of the range of capture groups contained within this group. -
getCaptureGroupsLow
public int getCaptureGroupsLow()Gets the (inclusive) lower bound of the range of capture groups in this term. In contrast togetEnclosedCaptureGroupsLow(), this range contains the group itself if it is a capturing group. -
setEnclosedCaptureGroupsLow
public void setEnclosedCaptureGroupsLow(int enclosedCaptureGroupsLow) Sets the (inclusive) lower bound of the range of capture groups contained within this group. -
getEnclosedCaptureGroupsHigh
public int getEnclosedCaptureGroupsHigh()Gets the (exclusive) upper bound of the range of capture groups contained within this group. -
getCaptureGroupsHigh
public int getCaptureGroupsHigh()Gets the (exclusive) upper bound of the range of capture groups in this term. -
setEnclosedCaptureGroupsHigh
public void setEnclosedCaptureGroupsHigh(int enclosedCaptureGroupsHigh) Sets the (exclusive) upper bound of the range of capture groups contained within this group. -
hasEnclosedCaptureGroups
public boolean hasEnclosedCaptureGroups() -
isAlwaysZeroWidth
public boolean isAlwaysZeroWidth()Returnstrueiff all alternatives of this group match only the empty string. -
isUnrollingCandidate
public boolean isUnrollingCandidate()Description copied from class:QuantifiableTermReturnstrueiff the parser should try to unroll this term's quantifier.- Specified by:
isUnrollingCandidatein classQuantifiableTerm
-
getAlternatives
Returns the list of alternatives that make up thisGroup.Elements should not be added or removed from this list. Use the
add(Sequence),insertFirst(Sequence)andaddSequence(RegexAST)methods instead. -
setAlternatives
-
getFirstAlternative
-
size
public int size() -
isEmpty
public boolean isEmpty() -
add
Adds a new alternative to this group. The new alternative will be appended to the end, meaning it will have the lowest priority among all the alternatives.- Parameters:
sequence-
-
insertFirst
Inserts a new alternative to this group. The new alternative will be inserted at the beginning, meaning it will have the highest priority among all the alternatives.- Parameters:
sequence-
-
addSequence
-
getLastAlternative
-
removeLastSequence
public void removeLastSequence() -
isLiteral
public boolean isLiteral() -
visitorHasNext
public boolean visitorHasNext()- Specified by:
visitorHasNextin interfaceRegexASTVisitorIterable
-
visitorGetNext
- Specified by:
visitorGetNextin interfaceRegexASTVisitorIterable
-
resetVisitorIterator
public void resetVisitorIterator()- Specified by:
resetVisitorIteratorin interfaceRegexASTVisitorIterable
-
alternativesToString
-
loopToString
-
equalsSemantic
- Specified by:
equalsSemanticin classQuantifiableTerm
-
toString
-
toJson
- Specified by:
toJsonin interfaceJsonConvertible
-