Package sc.parser

Class DiffContext


  • public class DiffContext
    extends java.lang.Object
    In order to perform an efficient reparse, we first make a pass over the old parse-node and the new text string to build up some context including: the first different parse node, the last different parse-node. These are the parse-nodes in the old parse-node tree which bracket the changed region. To help identify the border between the original unchanged text and the changed region we also store the set of changed-parents. We use the changed-parents to determine whether or not to traverse a parent node in the unchanged region. To detect the region of the file when the text is the "same again" we also store the last diff node. We start from the end of the file and walk the parse-node-tree in reverse looking for the first node hit from the end of the tree which is not the same. To help identify the boundary between the parse-nodes we can reuse at the end of the parse-node tree and the changed region in the text, we also store the last-node we fully visited before we encountered the changed region. As soon as we encounter this node, we can start reusing parse-nodes from the original parse node tree. We flag this by setting sameAgain = true. In order to start the same-again process as quickly as possible, all children of the last-visited node which have the same start index are also considered "last visited nodes". Any one of them can trip the sameAgain flag to true. We finally have two markers to determine the end of the changed region in the new text - endChangeNewOffset and endParseChangeNewOffset. They both start out the same - pointing to the index of the text which is the same again - i.e. newText[endChangeNewOffset] = oldText[endChangeOldOffset] and every subsequent char in the text is the same. When we encounter a node which parses-differently in the changed region which extends into the unchanged text, we push back the endParseChangeNewOffset to include this region which cannot be parsed the same - because we already parsed it differently.
    • Field Detail

      • debugDiffContext

        public static boolean debugDiffContext
    • Constructor Detail

      • DiffContext

        public DiffContext()
    • Method Detail

      • addChangedParent

        public void addChangedParent​(IParseNode parentParseNode)
      • getNewOffset

        public int getNewOffset()
      • getNewOffsetForOldPos

        public int getNewOffsetForOldPos​(int pos)
      • getNewOffsetForNewPos

        public int getNewOffsetForNewPos​(int pos)
      • getDiffOffset

        public int getDiffOffset()
      • setChangedRegion

        public void setChangedRegion​(Parser parser,
                                     boolean newVal)
      • setSameAgain

        public void setSameAgain​(Parser parser,
                                 boolean newVal)
      • resetCurrentIndex

        public java.lang.Object resetCurrentIndex​(Parser parser,
                                                  int newIndex)
      • restoreCurrentIndex

        public void restoreCurrentIndex​(Parser parser,
                                        int index,
                                        java.lang.Object semanticContext)
      • changeCurrentIndex

        public void changeCurrentIndex​(Parser parser,
                                       int newIndex)
      • updateForNewIndex

        public void updateForNewIndex​(int newIndex)
      • isAfterLastNode

        public boolean isAfterLastNode​(java.lang.Object node,
                                       boolean beforeMatch)