Example: Adding a parser for syntax checking - bobbylight/RSyntaxTextArea GitHub Wiki
Overview steps:
- Create an implementation of the
Parserinterface. To make it easy, useAbstractParseras a base class. - Then you'll need to write the
parse()method, which returns aParseResult. To make it easy, useDefaultParseResultas a base class. - The
ParseResultshould contain someParserNotices. If you useDefaultParserNoticeas a base class, then you just need to specify a line number and a message. - Call
addParseron the text area.
Example code:
class ExampleParser extends AbstractParser {
@Override
public ParseResult parse(RSyntaxDocument document, String style) {
DefaultParseResult result = new DefaultParseResult(this);
result.addNotice(new DefaultParserNotice(this, "Message", 4));
return result;
}
}
textArea.addParser(new ExampleParser());
A red squiggle underline will appear on line 4:
And a tooltip will appear when you move your mouse over the line: