Class Sequence

java.lang.Object
com.oracle.truffle.regex.tregex.parser.ast.RegexASTNode
com.oracle.truffle.regex.tregex.parser.ast.Sequence
All Implemented Interfaces:
RegexASTVisitorIterable, JsonConvertible

public final class Sequence extends RegexASTNode implements RegexASTVisitorIterable
A Sequence is a concatenation of Terms.

Sequences are used as the alternatives in a Group. They are the only subtype of RegexASTNode which does not extend Term. In order to coerce a Sequence into a Term, wrap it in a Group (as its only alternative).

Corresponds to the goal symbol Alternative in the ECMAScript RegExp syntax.

  • Method Details

    • copy

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

      public Sequence 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.
      Specified by:
      copyRecursive in class RegexASTNode
      Parameters:
      ast - RegexAST the new nodes should belong to.
      Returns:
      A deep copy of this node.
    • getParent

      public Group getParent()
      Description copied from class: RegexASTNode
      Gets the syntactic parent of this AST node.
      Overrides:
      getParent in class RegexASTNode
    • setParent

      public void setParent(RegexASTNode parent)
      Description copied from class: RegexASTNode
      Sets the syntactic parent of this AST node.
      Overrides:
      setParent in class RegexASTNode
      Parameters:
      parent -
    • getTerms

      public ArrayList<Term> getTerms()
      Returns the list of terms that constitute this Sequence.

      Note that elements should not be added or removed from this list. Use the methods add(Term) and removeLastTerm() instead.

    • isEmpty

      public boolean isEmpty()
    • size

      public int size()
    • getFirstTerm

      public Term getFirstTerm()
    • get

      public Term get(int i)
    • getLastTerm

      public Term getLastTerm()
    • add

      public void add(Term term)
      Adds a Term to the end of the Sequence.
      Parameters:
      term -
    • replace

      public void replace(int index, Term term)
      Replaces the term at position index with the given Term.
      Parameters:
      term -
    • removeTerm

      public void removeTerm(int i, CompilationBuffer compilationBuffer)
    • removeLastTerm

      public void removeLastTerm()
      Removes the last Term from this Sequence.
    • isFirstInGroup

      public boolean isFirstInGroup()
    • isLastInGroup

      public boolean isLastInGroup()
    • isPenultimateInGroup

      public boolean isPenultimateInGroup()
    • isLiteral

      public boolean isLiteral()
    • isSingleCharClass

      public boolean isSingleCharClass()
    • getEnclosedCaptureGroupsLow

      public int getEnclosedCaptureGroupsLow()
    • getEnclosedCaptureGroupsHigh

      public int getEnclosedCaptureGroupsHigh()
    • getSubTreeParent

      public RegexASTSubtreeRootNode getSubTreeParent()
      Description copied from class: RegexASTNode
      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.
      Specified by:
      getSubTreeParent in class RegexASTNode
    • visitorHasNext

      public boolean visitorHasNext()
      Specified by:
      visitorHasNext in interface RegexASTVisitorIterable
    • resetVisitorIterator

      public void resetVisitorIterator()
      Specified by:
      resetVisitorIterator in interface RegexASTVisitorIterable
    • visitorGetNext

      public RegexASTNode visitorGetNext(boolean reverse)
      Specified by:
      visitorGetNext in interface RegexASTVisitorIterable
    • equalsSemantic

      public boolean equalsSemantic(RegexASTNode obj)
      Specified by:
      equalsSemantic in class RegexASTNode
    • toString

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

      public JsonValue toJson()
      Specified by:
      toJson in interface JsonConvertible