Reuse of Parsers that can not parse line by line
Hellwig-SE opened this issue · comments
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.