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

77
LINES

< > BotCompany Repo | #1035120 // RSTADummyParser - just for forwarding the actual parser's error highlights

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (8198L) is out of date.

!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.
    
  // pair of input text, list of errors to show
  gettable Pair<S, L<Error>> errors;
  
  sclass Error {
    settable LineAndColumn start;
    settable LineAndColumn end;
    settable S msg;
  }

  @Override
  public ParseResult parse(RSyntaxDocument doc, String style) {
    var result = new DefaultParseResult(this);
    pcall {
      var p = this.errors;
      //printVars("RSTADummyParser.parse called", +p);
      if (p == null) ret result;
      S src = p.a;
      var errors = p.b;
      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, src)) {
        //print("RSTADummyParser: Wrong text");
        ret result;
      }
      
      // We're on the right text, convert messages and return them  
      //print("Have " + n2(errors, "error"));
      for (Error e : errors) {
        LineAndColumn start = e.start;
        LineAndColumn end = e.end;
        int lineStart = lineNrToCharIndex(text, start.line);
        int lineLength = lengthOfLine(text, start.line-1);
        /*int col = min(start.col, lineLength);
        int length = end.line > start.line
          // spanning multiple lines
          ? lineLength-(col-1)
          // start and end in same line
          : end.col-col;
        length = max(1, length);
        //print("Got error of length " + length + " at " + start.line + " / " + col);
        result.addNotice(new DefaultParserNotice(this,
          e.msg, start.line, col, length));*/
          
        //print("Got error of length " + lineLength + " at line " + start.line);
        result.addNotice(new DefaultParserNotice(this,
          e.msg, start.line-1, lineStart, lineLength));
      }
    }
    
    //print("Returning result");
    ret result;
  }
  
  void setErrors(S text, L<Error> errors, RSyntaxTextArea textArea) {
    this.errors = pair(text, errors);
    swing {
      textArea.forceReparsing(RSTADummyParser.this);
      //print("Forced reparsing");
    }
  }
  
  void install(RSyntaxTextArea textArea) swing {
    textArea.addParser(RSTADummyParser.this);
    //print("Installed " + this + " on " + classNameAndIdentity(textArea));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035120
Snippet name: RSTADummyParser - just for forwarding the actual parser's error highlights
Eternal ID of this version: #1035120/32
Text MD5: 5d4ac62a43e567859d654b5884dcaa22
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-05 19:27:24
Source code size: 2653 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 179 / 354
Version history: 31 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)
#1035126 - RSTADummyParser - just for forwarding the actual parser's error highlights (backup)