Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

56
LINES

< > BotCompany Repo | #1035126 // RSTADummyParser - just for forwarding the actual parser's error highlights (backup)

JavaX fragment (include)

!include once #1015780 // RSyntaxTextArea libs / imports [include]
 
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;

sclass RSTADummyParser extends org.fife.ui.rsyntaxtextarea.parser.AbstractParser {
  delegate ParseResult, DefaultParseResult, DefaultParserNotice
    to org.fife.ui.rsyntaxtextarea.parser.
    
  // list of errors to show. also used to verify that we're on the
  // correct text version
  gettable L<Error> errors;
  
  sclass Error {
    settable TokenRangeWithSrc tokenRange;
    settable S msg;
  }

  @Override
  public ParseResult parse(RSyntaxDocument doc, String style) ctex {
    var result = new DefaultParseResult(this);
    var errors = this.errors;
    if (empty(errors)) ret result;
    
    // if wrong text, temporarily return no errors
    // (forceReparse will be called by actual parser)
    S text = doc.getText(0, doc.getLength());
    if (!eq(text, first(errors).tokenRange.fullSourceText()))
      ret result;
    
    // We're on the right text, convert messages and return them  
    for (Error e : errors) {
      LineAndColumn start = e.tokenRange.startLineAndCol();
      LineAndColumn end = e.tokenRange.endLineAndCol();
      int length = end.line > start.line
        // spanning multiple lines
        ? lengthOfLine(text, start.line-1)-(start.col-1)
        // start and end in same line
        : end.col-start.col;
      result.addNotice(new DefaultParserNotice(this,
        e.msg, start.line-1, start.col-1, length));
    }
    
    ret result;
  }
  
  void setErrors(L<Error> errors, RSyntaxTextArea textArea) {
    this.errors = errors;
    swing {
      textArea.forceReparsing(RSTADummyParser.this);
    }
  }
  
  void install(RSyntaxTextArea textArea) swing {
    textArea.addParser(RSTADummyParser.this);
  }
}

Author comment

Began life as a copy of #1035120

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035126
Snippet name: RSTADummyParser - just for forwarding the actual parser's error highlights (backup)
Eternal ID of this version: #1035126/1
Text MD5: 53aec16e62441b53869950fdfd86ca1f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-30 17:32:40
Source code size: 1832 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 43 / 52
Referenced in: [show references]