PDA

View Full Version : highlighting text between the same symbols



kib2
10th November 2007, 16:27
Hi,

Untill now, it was rather easy to find my way highlighting things like C++ comments in QTextEdit, or whatever text inside different symbols, i.e between "<" and ">" on sereral lines with the states mechanism.

Now, I wanted to highlight things between the same symbol, i.e ''' and ''' (like trible simple strings in Python). The problem is that the 2 regexps matches the same symbol and so the same positions. The end and start symbols may or not be on the same line.

Does someone have any idea on how to solve such things ?
Thanks in advance.

elcuco
10th November 2007, 23:23
don't use regexps, but a normal state machine...?

kib2
11th November 2007, 00:41
I'm sorry about my ignorance on the subject Edulco, but I initially though QSyntaxHighlighter was a state machine. Am I wrong ? If so, where can I find some "simple" articles on the this ?

Thanks.

elcuco
11th November 2007, 21:53
no, it helps you to maintain a state machine.

Look at the implementation of "/*" in the examples, and assign the state 2, to the state found between "<>". This means that if you find "<", set the state to "2" and when you see ">" set the state to "0", since "1" is comment... well, you know how the rest goes.