Package sc.parser

Interface IParseNode

  • All Superinterfaces:
    java.lang.CharSequence, IParseResult
    All Known Implementing Classes:
    AbstractParseNode, ErrorParseNode, FormattedParseNode, FormattingParseNode, NewlineParseNode, ParentParseNode, ParseNode, PartialValueParseNode, PreErrorParseNode, SpacingParseNode

    public interface IParseNode
    extends java.lang.CharSequence, IParseResult
    The core interface for the parse-tree which is built by the parselets. This tree maps one-to-one to productions from the parselets tree and retains pointers back into the grammar so you can update the tree incrementally. Each parse node also may have a semantic value - the AST or behavioral tree that's created from the parse tree. There are fewer nodes in the semantic value tree and that's usually what the program manipulates. The semantic value points to it's top-level parse node if it implements the ISemanticNode interface (which is required for the bi-directional and incremental updates).

    We do occasionally compress the leaf-nodes of the parse-node tree for speed and probably should do more of that

    TODO: for performance - maybe this should only be an abstract class. Also we should use final methods for things which are not overridden as this is a high-bandwidth set of classes.
    • Method Detail

      • setParselet

        void setParselet​(Parselet p)
      • getSemanticValue

        java.lang.Object getSemanticValue()
      • setSemanticValue

        void setSemanticValue​(java.lang.Object value,
                              boolean clearOld,
                              boolean restore)
      • toDebugString

        java.lang.String toDebugString()
      • refersToSemanticValue

        boolean refersToSemanticValue​(java.lang.Object v)
      • reformat

        IParseNode reformat()
        Reformats the parse node - replacing any explicit spacing nodes with the generateParseNode in the tree. The next toString will then reformat the parse nodes
      • firstChar

        int firstChar()
        Returns the first character value produced or -1 if there is none
      • toSemanticString

        java.lang.CharSequence toSemanticString()
      • toSemanticStringLength

        int toSemanticStringLength()
      • getStartIndex

        int getStartIndex()
        Returns the offset in characters from the beginning of the file
      • getOrigStartIndex

        int getOrigStartIndex()
        If we have a parse-node which has been copied from an old definition, the original start index
      • getNewStartIndex

        int getNewStartIndex()
        If this parse-node has been reparsed already, this returns the new start index. Otherwise -1
      • setStartIndex

        void setStartIndex​(int s)
      • indexOf

        int indexOf​(java.lang.String subtr)
        Returns the index of the string relative to the start of this parse node
      • indexOf

        int indexOf​(java.lang.String subtr,
                    int fromIndex)
      • lastIndexOf

        int lastIndexOf​(java.lang.String subtr)
      • advanceStartIndex

        void advanceStartIndex​(int s)
        If you take a language string and reparse it this lets you advance the start index to where it originally existed in the file (e.g. for HTML attribute expressions which are not parsed as part of the original grammar)
      • length

        int length()
        Returns the number of characters in the parse node
        Specified by:
        length in interface java.lang.CharSequence
      • isEmpty

        boolean isEmpty()
      • formatString

        java.lang.CharSequence formatString​(java.lang.Object parSemVal,
                                            ParentParseNode parParseNode,
                                            int curChildIndex,
                                            boolean removeFormattingNodes)
        Like toString but provides a parent object to handle spacing with re-generated primitive string valued nodes which do not know their parent.
      • styleNode

        void styleNode​(IStyleAdapter adapter,
                       java.lang.Object parSemVal,
                       ParentParseNode parParseNode,
                       int curChildIndex)
        Just like formatString, we need to take an optional parent semantic value, parseNode, and childIndex so we know where this element falls in the context so we can do spacing properly
      • changeLanguage

        void changeLanguage​(Language lang)
      • updateSemanticValue

        void updateSemanticValue​(java.util.IdentityHashMap<java.lang.Object,​java.lang.Object> oldNewMap)
      • isCompressedNode

        boolean isCompressedNode()
      • computeLineNumberForNode

        void computeLineNumberForNode​(LineFormatContext ctx,
                                      IParseNode toFindPN)
        Internal method used to walk the parse tree to find the line number for a given parse node (which must be in the tree).
      • findParseNode

        IParseNode findParseNode​(int startIndex,
                                 Parselet matchParselet,
                                 boolean overlap)
        Find the parse node at the specified start index. If matchParselet is not null the match is only returned if it is the same as the parselet specified
      • getChildStartOffset

        int getChildStartOffset​(Parselet childParselet)
      • resetStartIndex

        int resetStartIndex​(int ix,
                            boolean validate,
                            boolean newIndex)
        After updating some parse nodes, you may need to reset the start indexes. This sets the start index to the one given and returns the start index to continue after this parse node.
      • getSemanticLength

        int getSemanticLength()
        Returns the length of the parse node eliminating any trailing whitespace
      • findStartDiff

        void findStartDiff​(DiffContext ctx,
                           boolean atEnd,
                           java.lang.Object parSemVal,
                           ParentParseNode parParseNode,
                           int childIx)
        Finds the first parse node whose text does not match the DiffContext
      • isErrorNode

        boolean isErrorNode()
        Returns true for ErrorParseNode or parse nodes which are part of an error
      • setErrorNode

        void setErrorNode​(boolean val)
      • isGeneratedTree

        boolean isGeneratedTree()
        Returns true if any nodes in this tree have been through the 'generate' process. These nodes might have formatting parse nodes that need to be replaced for some operations
      • getNumSemanticValues

        int getNumSemanticValues()
        Used for reparse only, this method determines how many semantic value elements were produced by this parse node. Returns 1 for scalar semantic values or for a repeat value, the number of elements in the semantic value array. It's not just the size of the semantic value List because during reparse, we combine all of the elements from multiple parse nodes into one List when there's one repeat array node which has a child parselet that's also a repeat array node. Instead, we look at the number of child parse nodes and use that to determine how many array values came from the this node.
      • diffParseNode

        void diffParseNode​(IParseNode other,
                           java.lang.StringBuilder diffs)
      • isIncomplete

        boolean isIncomplete()
        Returns true for error parse-nodes which are partial-parses - i.e. did not parse required chunks
      • getNodeCount

        int getNodeCount()
      • addParseErrors

        void addParseErrors​(java.util.List<ParseError> errors,
                            int max)
        For incremental parses, return the list of errors detected and continued in the parse-stream (useful for syntax highlighting)