public final class Group extends Term implements RegexASTVisitorIterable
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.
FLAG_CHARACTER_CLASS_WAS_SINGLE_CHAR, FLAG_EMPTY_GUARD, FLAG_GROUP_EXPANDED_QUANTIFIER, FLAG_GROUP_LOOP, FLAG_HAS_LOOPS, FLAG_LOOK_AROUND_NEGATED| Modifier and Type | Method and Description |
|---|---|
void |
add(Sequence sequence)
Adds a new alternative to this group.
|
Sequence |
addSequence(RegexAST ast)
Creates a new empty alternatives and adds it to the end of the list of alternatives.
|
String |
alternativesToString() |
Group |
copy(RegexAST ast,
boolean recursive)
Copy this node, in one of the following ways:
if
recursive is true, recursively copy this subtree. |
boolean |
equalsSemantic(RegexASTNode obj,
boolean ignoreQuantifier) |
ArrayList<Sequence> |
getAlternatives()
Returns the list of alternatives that make up this
Group. |
int |
getBoundaryIndexEnd()
Returns the index corresponding to this capture group's END in a result array returned by a
capture-group aware DFA.
|
int |
getBoundaryIndexStart()
Returns the index corresponding to this capture group's BEGIN in a result array returned by a
capture-group aware DFA.
|
int |
getEnclosedCaptureGroupsHigh()
Gets the (exclusive) upper bound of the range of capture groups contained within this group.
|
int |
getEnclosedCaptureGroupsLow()
Gets the (inclusive) lower bound of the range of capture groups contained within this group.
|
int |
getGroupNumber()
Returns the number of this capturing group.
|
Sequence |
getLastAlternative() |
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.
|
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.
|
boolean |
hasEnclosedCaptureGroups() |
void |
insertFirst(Sequence sequence)
Inserts a new alternative to this group.
|
boolean |
isCapturing()
Returns whether this group is a capturing group.
|
boolean |
isEmpty() |
boolean |
isExpandedQuantifier()
Indicates whether this
Group was inserted into the AST as the result of expanding
quantifier syntax (*, +, ?, {n,m}). |
boolean |
isLiteral() |
boolean |
isLoop()
Returns whether or not this group loops.
|
String |
loopToString() |
void |
removeLastSequence() |
void |
resetVisitorIterator() |
void |
setAlternatives(ArrayList<Sequence> alternatives) |
void |
setEnclosedCaptureGroupsHigh(int enclosedCaptureGroupsHigh)
Sets the (exclusive) upper bound of the range of capture groups contained within this group.
|
void |
setEnclosedCaptureGroupsLow(int enclosedCaptureGroupsLow)
Sets the (inclusive) lower bound of the range of capture groups contained within this group.
|
void |
setExpandedQuantifier(boolean expandedQuantifier)
Marks this
Group as being inserted into the AST as part of expanding quantifier
syntax (*, +, ?, {n,m}). |
void |
setGroupNumber(int groupNumber)
Marks this
Group as capturing and sets its group number. |
void |
setLoop(boolean loop)
Sets whether or this group should loop.
|
int |
size() |
JsonValue |
toJson() |
String |
toString() |
RegexASTNode |
visitorGetNext(boolean reverse) |
boolean |
visitorHasNext() |
equalsSemantic, getQuantifier, getSeqIndex, getSubTreeParent, hasQuantifier, quantifierToString, setQuantifier, setSeqIndexastNodeId, endsWithDollar, getId, getMaxPath, getMinPath, getParent, hasEmptyGuard, hasLoops, idInitialized, incMaxPath, incMaxPath, incMinPath, incMinPath, isDead, isFlagSet, isInLookAheadAssertion, isInLookBehindAssertion, isPrefix, markAsDead, setEmptyGuard, setEndsWithDollar, setEndsWithDollar, setFlag, setFlag, setHasLoops, setHasLoops, setId, setMaxPath, setMinPath, setParent, setPrefix, setStartsWithCaret, setStartsWithCaret, startsWithCaret, toJson, toStringWithIDpublic Group copy(RegexAST ast, boolean recursive)
RegexASTNoderecursive is true, recursively copy this subtree. This method should
be used instead of CopyVisitor if the copying process is required to be thread-safe.
public boolean isLoop()
public void setLoop(boolean loop)
loop - true if this group should loopGroup.isLoop()public boolean isExpandedQuantifier()
Group was inserted into the AST as the result of expanding
quantifier syntax (*, +, ?, {n,m}).
E.g., if A is some group, then:
public void setExpandedQuantifier(boolean expandedQuantifier)
Group as being inserted into the AST as part of expanding quantifier
syntax (*, +, ?, {n,m}).Group.isExpandedQuantifier()public int getGroupNumber()
public int getBoundaryIndexStart()
public int getBoundaryIndexEnd()
public static int groupNumberToBoundaryIndexStart(int groupNumber)
public static int groupNumberToBoundaryIndexEnd(int groupNumber)
public boolean isCapturing()
This is the case when this Group was built using the Group.Group(int) constructor or if
Group.setGroupNumber(int) was called.
public void setGroupNumber(int groupNumber)
Group as capturing and sets its group number.groupNumber - public int getEnclosedCaptureGroupsLow()
public void setEnclosedCaptureGroupsLow(int enclosedCaptureGroupsLow)
public int getEnclosedCaptureGroupsHigh()
public void setEnclosedCaptureGroupsHigh(int enclosedCaptureGroupsHigh)
public boolean hasEnclosedCaptureGroups()
public ArrayList<Sequence> getAlternatives()
Group.
Elements should not be added or removed from this list. Use the Group.add(Sequence),
Group.insertFirst(Sequence) and Group.addSequence(RegexAST) methods instead.
public int size()
public boolean isEmpty()
public void add(Sequence sequence)
sequence - public void insertFirst(Sequence sequence)
sequence - public Sequence addSequence(RegexAST ast)
ast - The AST that the new alternative should belong topublic Sequence getLastAlternative()
public void removeLastSequence()
public boolean isLiteral()
public boolean visitorHasNext()
visitorHasNext in interface RegexASTVisitorIterablepublic RegexASTNode visitorGetNext(boolean reverse)
visitorGetNext in interface RegexASTVisitorIterablepublic void resetVisitorIterator()
resetVisitorIterator in interface RegexASTVisitorIterablepublic String alternativesToString()
public String loopToString()
public boolean equalsSemantic(RegexASTNode obj, boolean ignoreQuantifier)
equalsSemantic in class Termpublic JsonValue toJson()
toJson in interface JsonConvertible