Class RegexASTBuilder
java.lang.Object
com.oracle.truffle.regex.tregex.parser.RegexASTBuilder
This class is used to generate regex ASTs. The provided methods append nodes to the AST.
-
Constructor Summary
ConstructorsConstructorDescriptionRegexASTBuilder(RegexLanguage language, RegexSource source, RegexFlags flags, boolean canExplodeUTF16, CompilationBuffer compilationBuffer) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBackReference(int groupNumber, boolean namedReference, boolean ignoreCase) voidvoidaddBackReference(Token.BackReference token, boolean ignoreCase) voidaddBackReference(Token.BackReference token, boolean ignoreCase, boolean ignoreCaseAltMode) Adds a newBackReferenceto the currentSequence.voidaddCaret()voidaddCharClass(CodePointSet charSet) voidaddCharClass(CodePointSet charSet, boolean wasSingleChar) voidaddCharClass(Token.CharacterClass token) Adds a newCharacterClassto the currentSequence.voidaddClassSet(Token.ClassSet token, CaseFoldData.CaseFoldUnfoldAlgorithm caseUnfoldAlgo) voidAdds a copy ofsourceGroupto the currentSequence.voidAdds a dead node (an empty character class) to the currentSequence.voidvoidaddPositionAssertion(Token token) Adds a newPositionAssertionto the currentSequence.voidaddQuantifier(Token.Quantifier quantifier) Adds a quantifier to the currentTerm.voidaddSubexpressionCall(int groupNumber) voidaddWordBoundaryAssertion(CodePointSet wordChars, CodePointSet nonWordChars) voidaddWordNonBoundaryAssertion(CodePointSet wordChars, CodePointSet nonWordChars) voidaddWordNonBoundaryAssertionPython(CodePointSet wordChars, CodePointSet nonWordChars) voidbooleanIndicates whether the builder is currently in the root group or in some nested group.Returns the currentGroup.intReturns the code position of the beginning (opening parenthesis) of the currentGroup(getCurGroup()).voidvoidpopGroup()voidClose and leave the current group.This is the build method of this Builder.voidvoidpushAtomicGroup(Token token) Creates and enters a new atomic group.voidvoidpushCaptureGroup(Token token) Creates and enters a new capture group.voidpushConditionalBackReferenceGroup(int referencedGroupNumber, boolean namedReference) voidCreates and enters a new conditional back-reference group.voidvoidCreates and enters a new non-capturing group.voidpushLookAheadAssertion(boolean negate) voidpushLookAheadAssertion(Token token, boolean negate) Creates and enters a new look-ahead assertion.voidpushLookBehindAssertion(boolean negate) voidpushLookBehindAssertion(Token token, boolean negate) Creates and enters a new look-behind assertion.voidThis should be called first after creating a newRegexASTBuilder.voidpushRootGroup(boolean rootCapture) LikepushRootGroup(), but allows creating a non-capturing root group.voidvoidReplaces the currentTermwith a dead node.voidsetOverrideSourceSection(com.oracle.truffle.api.source.SourceSection sourceSection) voidWraps the currentTermin an atomic group.voidWraps the currentTermin a non-capturing group.
-
Constructor Details
-
RegexASTBuilder
public RegexASTBuilder(RegexLanguage language, RegexSource source, RegexFlags flags, boolean canExplodeUTF16, CompilationBuffer compilationBuffer)
-
-
Method Details
-
getCompilationBuffer
-
getCurGroup
-
getCurSequence
-
getCurTerm
-
getCurGroupStartPosition
public int getCurGroupStartPosition()Returns the code position of the beginning (opening parenthesis) of the currentGroup(getCurGroup()). -
setOverrideSourceSection
public void setOverrideSourceSection(com.oracle.truffle.api.source.SourceSection sourceSection) -
clearOverrideSourceSection
public void clearOverrideSourceSection() -
curGroupIsRoot
public boolean curGroupIsRoot()Indicates whether the builder is currently in the root group or in some nested group.- Returns:
trueif the builder is in the root group
-
pushRootGroup
public void pushRootGroup()This should be called first after creating a newRegexASTBuilder. This will create and enter the root capture group (group number 0). -
pushRootGroup
public void pushRootGroup(boolean rootCapture) LikepushRootGroup(), but allows creating a non-capturing root group. This is useful for building intermediate ASTs that are then pasted into other ASTs. -
popRootGroup
This is the build method of this Builder. As such, it should be the last method you call on anRegexASTBuilderinstance.- Returns:
- the generated AST
-
pushGroup
Creates and enters a new non-capturing group. This call should be paired with a call topopGroup(com.oracle.truffle.regex.tregex.parser.Token).- Parameters:
token- aTokenwhose source section should be included in the group's source sections, ornullif none
-
pushGroup
public void pushGroup() -
pushCaptureGroup
Creates and enters a new capture group. This call should be paired with a call topopGroup(com.oracle.truffle.regex.tregex.parser.Token).- Parameters:
token- aTokenwhose source section should be included in the group's source sections, ornullif none
-
pushCaptureGroup
public void pushCaptureGroup() -
pushLookAheadAssertion
Creates and enters a new look-ahead assertion. This call should be paired with a call topopGroup(com.oracle.truffle.regex.tregex.parser.Token).- Parameters:
token- aTokenwhose source section should be included in the assertion's source sections, ornullif nonenegate-trueif the look-ahead assertion is to be negative
-
pushLookAheadAssertion
public void pushLookAheadAssertion(boolean negate) -
pushLookBehindAssertion
Creates and enters a new look-behind assertion. This call should be paired with a call topopGroup(com.oracle.truffle.regex.tregex.parser.Token).- Parameters:
token- aTokenwhose source section should be included in the assertion's source sections, ornullif nonenegate-trueif the look-behind assertion is to be negative
-
pushLookBehindAssertion
public void pushLookBehindAssertion(boolean negate) -
pushAtomicGroup
Creates and enters a new atomic group. This call should be paired with a call topopGroup(com.oracle.truffle.regex.tregex.parser.Token).- Parameters:
token- aTokenwhose source section should be included in the group's source sections, ornullif none
-
pushAtomicGroup
public void pushAtomicGroup() -
pushConditionalBackReferenceGroup
Creates and enters a new conditional back-reference group. This call should be paired with a call topopGroup(com.oracle.truffle.regex.tregex.parser.Token).- Parameters:
token- aTokenwhose source section should be included in the group's source sections, ornullif none
-
pushConditionalBackReferenceGroup
public void pushConditionalBackReferenceGroup(int referencedGroupNumber, boolean namedReference) -
popGroup
Close and leave the current group. This should be paired either withpushGroup(Token),pushCaptureGroup(Token),pushLookAheadAssertion(Token, boolean)orpushLookBehindAssertion(Token, boolean).- Parameters:
token- aTokenwhose source section should be included in the group's or assertion's source sections, ornullif none
-
popGroup
public void popGroup() -
nextSequence
-
addCharClass
Adds a newCharacterClassto the currentSequence.- Parameters:
token- aside from the source sections, the token most importantly contains the set of code points to be included in the character class and a flag indicating whether it corresponds to a single character in the regex (i.e. a literal or an escaped character)
-
addCharClass
-
addCharClass
-
addClassSet
- Parameters:
token- aside from the source sections, the token most importantly contains the set of code points and strings to be included in the class set
-
addBackReference
-
addBackReference
-
addBackReference
public void addBackReference(Token.BackReference token, boolean ignoreCase, boolean ignoreCaseAltMode) Adds a newBackReferenceto the currentSequence.- Parameters:
token- aside from the source sections, this contains the number of the group being referenced
-
addBackReference
public void addBackReference(int groupNumber, boolean namedReference, boolean ignoreCase) -
addSubexpressionCall
public void addSubexpressionCall(int groupNumber) -
addPositionAssertion
Adds a newPositionAssertionto the currentSequence.- Parameters:
token- aside from the source sections, the kind of this token indicates whether this is the^assertion or the$assertion
-
addCaret
public void addCaret() -
addDollar
public void addDollar() -
addQuantifier
Adds a quantifier to the currentTerm.- Parameters:
quantifier- this token contains a specification of the quantifier's semantics, along with the source section data
-
addCopy
-
removeCurTerm
-
addDeadNode
public void addDeadNode()Adds a dead node (an empty character class) to the currentSequence. -
replaceCurTermWithDeadNode
public void replaceCurTermWithDeadNode()Replaces the currentTermwith a dead node. -
wrapCurTermInGroup
public void wrapCurTermInGroup()Wraps the currentTermin a non-capturing group. -
wrapCurTermInAtomicGroup
public void wrapCurTermInAtomicGroup()Wraps the currentTermin an atomic group. This can be useful when implementing possessive quantifiers. -
addWordBoundaryAssertion
-
addWordNonBoundaryAssertion
-
addWordNonBoundaryAssertionPython
-