Class SyntaxTree

java.lang.Object
quickparse.parsing.syntaxtree.SyntaxTree
Direct Known Subclasses:
ConstructNode, TokenNode

public abstract class SyntaxTree
extends java.lang.Object
Represents a generic node of a syntax tree, which is the result of a parsing process. A syntax tree node represents a char sequence matched by a grammar rule.
A generic node of a syntax tree has four properties:
  • Source: the source char sequence that has been parsed;
  • Start index: the position in the Source at which the matched char sequence starts;
  • End index: the position in the Source at which the matched char sequence ends;
  • Name: the name of the Construct or Token matched (i.e., the head symbol of the grammar rule matched);
  • Field Summary

    Fields 
    Modifier and Type Field Description
    int end  
    java.lang.String name  
    java.lang.CharSequence source  
    int start  
    java.lang.CharSequence value  
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected SyntaxTree​(java.lang.CharSequence source, int start, int end, java.lang.String name)  
  • Method Summary

    Modifier and Type Method Description
    abstract <STV extends SyntaxTreeVisitor>
    STV
    accept​(STV syntaxTreeVisitor)
    Accepts a SyntaxTreeVisitor and uses it to visit this node and its eventually present children.
    boolean equals​(java.lang.Object o)  
    int hashCode()  
    java.lang.String toString()
    Encodes this structure and its hierarchy in a string.
    abstract java.lang.String toString​(int level)
    Encodes this structure and its hierarchy in a string.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • source

      public final java.lang.CharSequence source
    • start

      public final int start
    • end

      public final int end
    • name

      public final java.lang.String name
    • value

      public final java.lang.CharSequence value
  • Constructor Details

    • SyntaxTree

      protected SyntaxTree​(java.lang.CharSequence source, int start, int end, java.lang.String name)
  • Method Details

    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Encodes this structure and its hierarchy in a string.
      Overrides:
      toString in class java.lang.Object
      Returns:
      a String object
      See Also:
      Object.toString(), toString(int)
    • toString

      public abstract java.lang.String toString​(int level)
      Encodes this structure and its hierarchy in a string.
      Parameters:
      level - The deep level in the hierarchy.
      Returns:
      a String object
      See Also:
      toString()
    • accept

      public abstract <STV extends SyntaxTreeVisitor> STV accept​(STV syntaxTreeVisitor)
      Accepts a SyntaxTreeVisitor and uses it to visit this node and its eventually present children.
      Type Parameters:
      STV - the sub-type of SyntaxTreeVisitor
      Parameters:
      syntaxTreeVisitor - the visitor to accept
      Returns:
      the same visitor given as input