bobbylight / RSyntaxTextArea

A syntax highlighting, code folding text editor for Java Swing applications.
BSD 3-Clause "New" or "Revised" License
1.12k stars 259 forks source link

Reuse of Parsers that can not parse line by line #454

Closed Hellwig-SE closed 2 years ago

Hellwig-SE commented 2 years ago

Describe the solution you'd like I want to reuse a parser for syntax highlighting that provides an interface as following:

List<Token> parse(String content) throws ParseException;

Parsing can not be restarted in a certain parser state, which is required by RSyntaxDocument#getTokenListForLine.

Since RSyntaxDocument#getTokenListForLine is marked final, i can not override this behaviour and therefore can not reuse the parser.

Are there any workarounds? Not really

Additional context

Solution A solution would be to remove the final modifier from RSyntaxDocument#getTokenListForLine. Then a subclass of the RSyntaxDocument can be created that parses the whole document on each change and caches the tokens by line. This cache is then used to answer RSyntaxDocument#getTokenListForLine as expected by the rest of the system.