Class ConditionalBackReferenceGroup

All Implemented Interfaces:
AbstractState<Term,ASTTransition>, RegexASTVisitorIterable, JsonConvertible

public final class ConditionalBackReferenceGroup extends Group
Conditional back-reference groups represent the following construct found, e.g., in Python:

(?(group_name)then_branch|else_branch

Every conditional back-reference group has exactly 2 alternatives. The first alternative can only be taken if the referenced group was matched and the second alternative can be taken only if the referenced group was *not* matched.

  • Constructor Details

    • ConditionalBackReferenceGroup

      public ConditionalBackReferenceGroup(int referencedGroupNumber)
      Creates an empty conditional back-reference group. It should later be filled with exactly 2 Sequences as its alternatives.
      Parameters:
      referencedGroupNumber - The number of the capture group referenced in the condition.
  • Method Details

    • getReferencedGroupNumber

      public int getReferencedGroupNumber()
      Returns the index of the capture group that is referenced by this conditional expression.
    • copy

      Description copied from class: RegexASTNode
      Copy this node only, without any child nodes. The ID and minPath of the copied nodes is left unset.
      Overrides:
      copy in class Group
      Parameters:
      ast - RegexAST the node should belong to.
      Returns:
      A shallow copy of this node.
    • copyRecursive

      public ConditionalBackReferenceGroup copyRecursive(RegexAST ast, CompilationBuffer compilationBuffer)
      Description copied from class: RegexASTNode
      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.
      Overrides:
      copyRecursive in class Group
      Parameters:
      ast - RegexAST the new nodes should belong to.
      Returns:
      A deep copy of this node.
    • equalsSemantic

      public boolean equalsSemantic(RegexASTNode obj, boolean ignoreQuantifier)
      Overrides:
      equalsSemantic in class Group
    • toString

      public String toString()
      Overrides:
      toString in class Group
    • toJson

      public JsonValue toJson()
      Specified by:
      toJson in interface JsonConvertible
      Overrides:
      toJson in class Group