-
Notifications
You must be signed in to change notification settings - Fork 260
Example: Adding a parser for syntax checking
Peter Froud edited this page May 24, 2023
·
2 revisions
Overview steps:
- Create an implementation of the
Parser
interface. To make it easy, useAbstractParser
as a base class. - Then you'll need to write the
parse()
method, which returns aParseResult
. To make it easy, useDefaultParseResult
as a base class. - The
ParseResult
should contain someParserNotice
s. If you useDefaultParserNotice
as a base class, then you just need to specify a line number and a message. - Call
addParser
on 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: