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.

1  
!include once #1015780 // RSyntaxTextArea libs / imports [include]
2  
 
3  
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
4  
5  
sclass RSTADummyParser extends org.fife.ui.rsyntaxtextarea.parser.AbstractParser {
6  
  delegate ParseResult, DefaultParseResult, DefaultParserNotice
7  
    to org.fife.ui.rsyntaxtextarea.parser.
8  
    
9  
  // pair of input text, list of errors to show
10  
  gettable Pair<S, L<Error>> errors;
11  
  
12  
  sclass Error {
13  
    settable LineAndColumn start;
14  
    settable LineAndColumn end;
15  
    settable S msg;
16  
  }
17  
18  
  @Override
19  
  public ParseResult parse(RSyntaxDocument doc, String style) {
20  
    var result = new DefaultParseResult(this);
21  
    pcall {
22  
      var p = this.errors;
23  
      //printVars("RSTADummyParser.parse called", +p);
24  
      if (p == null) ret result;
25  
      S src = p.a;
26  
      var errors = p.b;
27  
      if (empty(errors)) ret result;
28  
      
29  
      // if wrong text, temporarily return no errors
30  
      // (forceReparse will be called by actual parser)
31  
      S text = doc.getText(0, doc.getLength());
32  
      if (!eq(text, src)) {
33  
        //print("RSTADummyParser: Wrong text");
34  
        ret result;
35  
      }
36  
      
37  
      // We're on the right text, convert messages and return them  
38  
      //print("Have " + n2(errors, "error"));
39  
      for (Error e : errors) {
40  
        LineAndColumn start = e.start;
41  
        LineAndColumn end = e.end;
42  
        int lineStart = lineNrToCharIndex(text, start.line);
43  
        int lineLength = lengthOfLine(text, start.line-1);
44  
        /*int col = min(start.col, lineLength);
45  
        int length = end.line > start.line
46  
          // spanning multiple lines
47  
          ? lineLength-(col-1)
48  
          // start and end in same line
49  
          : end.col-col;
50  
        length = max(1, length);
51  
        //print("Got error of length " + length + " at " + start.line + " / " + col);
52  
        result.addNotice(new DefaultParserNotice(this,
53  
          e.msg, start.line, col, length));*/
54  
          
55  
        //print("Got error of length " + lineLength + " at line " + start.line);
56  
        result.addNotice(new DefaultParserNotice(this,
57  
          e.msg, start.line-1, lineStart, lineLength));
58  
      }
59  
    }
60  
    
61  
    //print("Returning result");
62  
    ret result;
63  
  }
64  
  
65  
  void setErrors(S text, L<Error> errors, RSyntaxTextArea textArea) {
66  
    this.errors = pair(text, errors);
67  
    swing {
68  
      textArea.forceReparsing(RSTADummyParser.this);
69  
      //print("Forced reparsing");
70  
    }
71  
  }
72  
  
73  
  void install(RSyntaxTextArea textArea) swing {
74  
    textArea.addParser(RSTADummyParser.this);
75  
    //print("Installed " + this + " on " + classNameAndIdentity(textArea));
76  
  }
77  
}

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: 178 / 354
Version history: 31 change(s)
Referenced in: [show references]