Bostjan Mihoric:
> I do C parsing in my plugin and have all identifier info available. What I'd like is something like lexer asking me about whether some word is a type keyword, and I would give it an answer. Other than that, it would do all other lexing just as usual.
If the plugin can fully parse C then its should be able to take over the role of providing lexical data over the file.
> If possible, I'd like to avoid writing my own lexer, as I'm unsure how complicated that is (and for other reasons, like Notepad++ having it's own settings for lexers). I can communicate with Scintilla directly, and can also subclass it if necessary, intercepting all message communication (Windows mechanism).
>
> Is it possible to extend an existing lexer in such a way?
It is difficult to extend lexers in this way and there can be unexpected patterns of reentrancy that can upset implementations. For example, fold discovery can lead to nested lexing to find the end of a fold structure.
This is layering lexers where later lexers process the result of earlier lexers. Other examples include recognising URLs in the text or spelling mistakes. Scintilla does not have good support for this. Scintilla could be extended to change the current single ‘endStyled’ field into a list of positions, one for each lexer in a stack. Then, when styled text is needed, each of the lexers is called to advance its ‘endStyled’ up to the limit from earlier lexers.
While Scintilla does not provide support for this, it can be implemented in a container by watching for modification and style modification events.
An issue is how the new styling is added to the style state since the base lexer will not understand any style values introduced by the later lexers. Using indicators can avoid changing style values and is a good approach for URLs and similar. Indicators can also change the foreground colour of text but they cannot change font, bold, or italics.
> The only thing I don't understand is, why does SCI_CLEARDOCUMENTSTYLE clear styles, but generates no new lexing requests?
> Text remains unstyled afterwards…?
It zeroes all the style bytes. The application may want to use a non-standard approach to styling at this point. If you want to start styling from some position, call SCI_STARTSTYLING.
Neil