Class RegexASTNode

java.lang.Object
com.oracle.truffle.regex.tregex.parser.ast.RegexASTNode
All Implemented Interfaces:
JsonConvertible
Direct Known Subclasses:
Sequence, Term

public abstract class RegexASTNode extends Object implements JsonConvertible
  • Constructor Details

    • RegexASTNode

      protected RegexASTNode()
    • RegexASTNode

      protected RegexASTNode(RegexASTNode copy)
  • Method Details

    • copy

      public abstract RegexASTNode copy(RegexAST ast)
      Copy this node only, without any child nodes. The ID and minPath of the copied nodes is left unset.
      Parameters:
      ast - RegexAST the node should belong to.
      Returns:
      A shallow copy of this node.
    • copyRecursive

      public abstract RegexASTNode copyRecursive(RegexAST ast, CompilationBuffer compilationBuffer)
      Recursively copy this subtree. This method should be used instead of CopyVisitor if the copying process is required to be thread-safe. The ID and minPath of the copied nodes is left unset.
      Parameters:
      ast - RegexAST the new nodes should belong to.
      Returns:
      A deep copy of this node.
    • equalsSemantic

      public abstract boolean equalsSemantic(RegexASTNode obj)
    • idInitialized

      public boolean idInitialized()
    • getId

      public final int getId()
    • setId

      public final void setId(int id)
    • getParent

      public RegexASTNode getParent()
      Gets the syntactic parent of this AST node.
    • setParent

      public void setParent(RegexASTNode parent)
      Sets the syntactic parent of this AST node.
      Parameters:
      parent -
    • isFlagSet

      protected boolean isFlagSet(int flag)
    • setFlag

      protected void setFlag(int flag)
    • getFlags

      protected int getFlags(int mask)
    • setFlags

      protected void setFlags(int newFlags, int mask)
      Update all flags denoted by mask with the values from newFlags.
    • setFlag

      protected void setFlag(int flag, boolean value)
    • markAsDead

      public void markAsDead()
      Marks the node as dead, i.e. unmatchable.
    • setDead

      public void setDead(boolean dead)
    • isDead

      public boolean isDead()
      Returns whether the node is dead, i.e. unmatchable.
    • isPrefix

      public boolean isPrefix()
      This flag marks all nodes that were inserted into the AST for look-behind matching, see MarkLookBehindEntriesVisitor and RegexAST.createPrefix().
      Returns:
      true if this node belongs to an inserted prefix construct, otherwise false.
    • setPrefix

      public void setPrefix()
      Sets the isPrefix() flag to true.
      See Also:
    • hasEmptyGuard

      public boolean hasEmptyGuard()
      Indicates whether this node should be allowed to match the empty string.
      Returns:
      true if this node is not allowed to match the empty string
    • setEmptyGuard

      public void setEmptyGuard(boolean emptyGuard)
    • hasCaret

      public boolean hasCaret()
      Subexpression contains "^".
    • setHasCaret

      public void setHasCaret()
    • setHasCaret

      public void setHasCaret(boolean hasCaret)
    • hasDollar

      public boolean hasDollar()
      Subexpression contains "$".
    • setHasDollar

      public void setHasDollar()
    • setHasDollar

      public void setHasDollar(boolean hasDollar)
    • startsWithCaret

      public boolean startsWithCaret()
      This subexpression is dominated by "^".
    • setStartsWithCaret

      public void setStartsWithCaret()
    • setStartsWithCaret

      public void setStartsWithCaret(boolean startsWithCaret)
    • endsWithDollar

      public boolean endsWithDollar()
      All paths out of this subexpression go through "$".
    • setEndsWithDollar

      public void setEndsWithDollar()
    • setEndsWithDollar

      public void setEndsWithDollar(boolean endsWithDollar)
    • hasLoops

      public boolean hasLoops()
      Subexpression contains loops.
    • setHasLoops

      public void setHasLoops()
    • setHasLoops

      public void setHasLoops(boolean hasLoops)
    • hasQuantifiers

      public boolean hasQuantifiers()
      Subexpression contains not unrolled quantifiers.
    • setHasQuantifiers

      public void setHasQuantifiers()
    • hasCaptureGroups

      public boolean hasCaptureGroups()
      Subexpression contains capturing groups.
    • setHasCaptureGroups

      public void setHasCaptureGroups()
    • hasLookAheads

      public boolean hasLookAheads()
      Subexpression contains look-ahead assertions.
    • setHasLookAheads

      public void setHasLookAheads()
    • hasLookBehinds

      public boolean hasLookBehinds()
      Subexpression contains look-behind assertions.
    • setHasLookBehinds

      public void setHasLookBehinds()
    • hasBackReferences

      public boolean hasBackReferences()
      Subexpression contains back-references.
    • setHasBackReferences

      public void setHasBackReferences()
    • isExpandedQuantifier

      public boolean isExpandedQuantifier()
      Indicates whether this RegexASTNode was inserted into the AST as the result of expanding quantifier syntax (*, +, ?, {n,m}). E.g., if A is some term, then:
      • A* is expanded as (A|)*
      • A*? is expanded as (|A)*
      • A+ is expanded as A(A|)*
      • A+? is expanded as A(|A)*
      • A? is expanded as (A|)
      • A?? is expanded as (|A)
      • A{2,4} is expanded as AA(A(A|)|)
      • A{2,4}? is expanded as AA(|A(|A))
      where (X|Y) is a group with alternatives X and Y and (X|Y)* is a looping group with alternatives X and Y. In the examples above, all of the occurrences of A in the expansions as well as the additional empty Sequences would be marked with this flag.
    • setExpandedQuantifier

      public void setExpandedQuantifier(boolean expandedQuantifier)
      Marks this RegexASTNode as being inserted into the AST as part of expanding quantifier syntax (*, +, ?, {n,m}).
      See Also:
    • isMandatoryUnrolledQuantifier

      public boolean isMandatoryUnrolledQuantifier()
      Indicates whether this RegexASTNode represents a mandatory copy of a quantified term after unrolling. E.g., in the expansion of A{2,4}, which is AA(A(A|)|), the first two occurrences of A are marked with this flag.
    • setMandatoryUnrolledQuantifier

      public void setMandatoryUnrolledQuantifier(boolean mandatoryUnrolledQuantifier)
      Marks this RegexASTNode as being inserted into the AST as part of unrolling the mandatory part of a quantified term.
      See Also:
    • isQuantifierPassThroughSequence

      public boolean isQuantifierPassThroughSequence()
      Indicates whether this node is an empty Sequence inserted as an early escape alternative when unrolling a quantifier expression. E.g., in the expansion of A{2,4}, which is AA(A(A|_)|_), the two _ characters show the two empty sequences marked with this flag.
    • setQuantifierPassThroughSequence

      public void setQuantifierPassThroughSequence(boolean quantifierPassThroughSequence)
      Marks this empty Sequence as being inserted into the AST as part of unrolling the optional suffix of a quantified term.
      See Also:
    • getMinPath

      public int getMinPath()
    • setMinPath

      public void setMinPath(int n)
    • incMinPath

      public void incMinPath()
    • incMinPath

      public void incMinPath(int n)
    • getMaxPath

      public int getMaxPath()
    • setMaxPath

      public void setMaxPath(int n)
    • incMaxPath

      public void incMaxPath()
    • incMaxPath

      public void incMaxPath(int n)
    • getPrefixLengthMin

      public int getPrefixLengthMin()
    • setPrefixLengthMin

      public void setPrefixLengthMin(int prefixLengthMin)
    • getPrefixLengthMax

      public int getPrefixLengthMax()
    • setPrefixLengthMax

      public void setPrefixLengthMax(int prefixLengthMax)
    • hasVariablePrefixLength

      public boolean hasVariablePrefixLength()
    • getSubTreeParent

      public abstract RegexASTSubtreeRootNode getSubTreeParent()
      Returns the subtree root node that this node is a part of. If this node is nested inside several look-around assertion nodes, returns the innermost one that contains this node. Every AST node should have a subtree parent, but nodes implicitly generated by RegexAST.getNFAAnchoredInitialState(int) and RegexAST.getNFAUnAnchoredInitialState(int) technically don't belong to the AST, so they will return null.
    • isInLookBehindAssertion

      public boolean isInLookBehindAssertion()
    • isInLookAheadAssertion

      public boolean isInLookAheadAssertion()
    • toStringWithID

      public String toStringWithID()
    • astNodeId

      protected static JsonValue astNodeId(RegexASTNode astNode)
    • isBackReference

      public boolean isBackReference()
    • isCharacterClass

      public boolean isCharacterClass()
    • isGroup

      public boolean isGroup()
    • isGroupWithGuards

      public boolean isGroupWithGuards()
    • isConditionalBackReferenceGroup

      public boolean isConditionalBackReferenceGroup()
    • isLookAroundAssertion

      public boolean isLookAroundAssertion()
    • isLookAheadAssertion

      public boolean isLookAheadAssertion()
    • isLookBehindAssertion

      public boolean isLookBehindAssertion()
    • isAtomicGroup

      public boolean isAtomicGroup()
    • isMatchFound

      public boolean isMatchFound()
    • isPositionAssertion

      public boolean isPositionAssertion()
    • isQuantifiableTerm

      public boolean isQuantifiableTerm()
    • isSubexpressionCall

      public boolean isSubexpressionCall()
    • isRoot

      public boolean isRoot()
    • isSubtreeRoot

      public boolean isSubtreeRoot()
    • isSequence

      public boolean isSequence()
    • isCaret

      public boolean isCaret()
    • isDollar

      public boolean isDollar()
    • asBackReference

      public BackReference asBackReference()
    • asCharacterClass

      public CharacterClass asCharacterClass()
    • asGroup

      public Group asGroup()
    • asConditionalBackReferenceGroup

      public ConditionalBackReferenceGroup asConditionalBackReferenceGroup()
    • asLookAroundAssertion

      public LookAroundAssertion asLookAroundAssertion()
    • asLookAheadAssertion

      public LookAheadAssertion asLookAheadAssertion()
    • asLookBehindAssertion

      public LookBehindAssertion asLookBehindAssertion()
    • asAtomicGroup

      public AtomicGroup asAtomicGroup()
    • asSubtreeRootNode

      public RegexASTSubtreeRootNode asSubtreeRootNode()
    • asMatchFound

      public MatchFound asMatchFound()
    • asPositionAssertion

      public PositionAssertion asPositionAssertion()
    • asQuantifiableTerm

      public QuantifiableTerm asQuantifiableTerm()
    • asSequence

      public Sequence asSequence()
    • asSubexpressionCall

      public SubexpressionCall asSubexpressionCall()
    • toJson

      protected JsonObject toJson(String typeName)