docs: protected void parseDocument(int offset, int length) throws BadLocationException {
          // initialize the segment with the complete document so the segment doesn't
          // have an underlying gap in the buffer
          styledDocument.getText(0, styledDocument.getLength(), segment);
          
          buffer = CharBuffer.wrap(segment.array).asReadOnlyBuffer();
          
          // initialize the lexer if necessary
          if (!lexer.isInitialized()) {
              // prime the parser and reparse whole document
              lexer.initialize();
              offset = 0;
              length = styledDocument.getLength();
          }
          else {
              int end = offset + length;
              offset = calcBeginParse(offset);
              length = calcEndParse(end) - offset;
              
              // clean the tree by ensuring multi line styles are reset in area
              // of parsing
              SortedSet set = mlTextRunSet.subSet(offset,
                      offset + length);
              if (set != null) {
                  set.clear();
              }
          }
          
          // parse the document
          lexer.parse(buffer, offset, length);
      }