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)

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  
  // list of errors to show. also used to verify that we're on the
10  
  // correct text version
11  
  gettable L<Error> errors;
12  
  
13  
  sclass Error {
14  
    settable TokenRangeWithSrc tokenRange;
15  
    settable S msg;
16  
  }
17  
18  
  @Override
19  
  public ParseResult parse(RSyntaxDocument doc, String style) ctex {
20  
    var result = new DefaultParseResult(this);
21  
    var errors = this.errors;
22  
    if (empty(errors)) ret result;
23  
    
24  
    // if wrong text, temporarily return no errors
25  
    // (forceReparse will be called by actual parser)
26  
    S text = doc.getText(0, doc.getLength());
27  
    if (!eq(text, first(errors).tokenRange.fullSourceText()))
28  
      ret result;
29  
    
30  
    // We're on the right text, convert messages and return them  
31  
    for (Error e : errors) {
32  
      LineAndColumn start = e.tokenRange.startLineAndCol();
33  
      LineAndColumn end = e.tokenRange.endLineAndCol();
34  
      int length = end.line > start.line
35  
        // spanning multiple lines
36  
        ? lengthOfLine(text, start.line-1)-(start.col-1)
37  
        // start and end in same line
38  
        : end.col-start.col;
39  
      result.addNotice(new DefaultParserNotice(this,
40  
        e.msg, start.line-1, start.col-1, length));
41  
    }
42  
    
43  
    ret result;
44  
  }
45  
  
46  
  void setErrors(L<Error> errors, RSyntaxTextArea textArea) {
47  
    this.errors = errors;
48  
    swing {
49  
      textArea.forceReparsing(RSTADummyParser.this);
50  
    }
51  
  }
52  
  
53  
  void install(RSyntaxTextArea textArea) swing {
54  
    textArea.addParser(RSTADummyParser.this);
55  
  }
56  
}

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: 48 / 60
Referenced in: [show references]