Quote Originally Posted by wysota View Post
Yes, that's correct. But as you are using a very general highlighting mechanism it is possible that for some languages changing the state of current paragraph will change the state of previous paragraphs. How do you want to cope with that? From what I see this highlighter is meant to work on complete files, not parts of it, so you can't guarantee this won't happen.
The executable source-highlight works on a complete file, but the code that it uses to highlight the file, operates on single lines, so its library can also operate on a single line, keeping track of the last highlighting state entered (and the user code can query this, store the stack, and set it back).

As for the situation you're describing, it is the QSyntaxHighlighter code itself that will take care of re-highlighting the previous paragraphs, if I didn't get it wrong, otherwise such situations couldn't be handled with QSyntaxHighlighter at all, am I wrong?

QSyntaxHighlighter only operates on a subset of possible situations - it is limited but in a sensible way. You are trying to work around those limitations which can result in breaking the mechanism. It might be easier to build your own from scratch without using QSyntaxHighlighter - after all this is a quite stupid class, it's not hard to write your own highlighting engine.
But it takes care of checking whether other parts of the file must be highlighted again (by relying on the current and previous state).

However, I'll try to implement what I meant now that I downloaded the source of Qt 4.4 and finally they added currentBlock() in QSyntaxHighlighter!