GNOME Bugzilla – Bug 140097
Implement some method to prioritize patterns
Last modified: 2014-02-15 12:53:14 UTC
Sometimes two patterns can match the *exact same string*. Currently GtkSourceView prefers the pattern which can match the longer string, but if two patterns match the same number of characters the choice is random in practice. The current highlighting engine should provide some way to prioritize one pattern over the other. The obvious mechanism would be to give them priority according to the order in which they appear in the .lang file.
Is someone already in the midst of working on this? If so, I'd like to get in contact and help; if not, I'd be happy to at least get started taking crack at it on my own.
not sure why this one was NEEDINFO... reopening: this is a known issue of the current engine and we should at least have it visible in bugzilla so that we can adress the problem in the new engine. Muntyan: I am CC'ing you since you asked about priorities in the current engine.
Engine looks for a match which has least start offset; then, if two matches start at the same offset, it chooses the one which comes first in lang file (it doesn't really choose, it just tries contexts in order).
New engine doesn't have this issue (if there was one). It does what's said in comment #3; if it's wrong or not good then it's a design issue with new engine, and new bug should be opened.
But the *styles* have a fixed precedence, regardless of order in the .lang file. This is the key problem -- for example, a "string" type always overrides "keyword" types. Currently, it is impossible to highlight keywords inside a string, even if we wanted to. There needs to be a way to say "this group of keywords is more important than string highlighting" so we can get, e.g., "$foo" to highlight in a PHP string, or "\n" to highlight in a C/C++/etc. string. This problem is by no means limited to strings, its just that strings are one of the easiest places to see this deficiency at work.
This is done by including one context into another, you can highlight keywords if you like. Now, styles are composed, so e.g. if you have blue string and bold keywords, so keyword in a string will be bold blue. Not sure if you mean it's a problem, but it's certainly as it should be (and you can make keywords bold-and-black in fact). By the way, escape sequences are highlighted in C strings right now. So, there are certainly bugs, but they are not as simple as this one (and the bug from the *title* is certainly not an issue anymore). Please open new bugs for specific issues, this old one must die. Note that I am talking about gtksourceview-2 which recently went onto svn trunk, i.e. the new unreleased-yet highlighting engine.
Sorry for spam. Marking this as FIXED since there are bugs depending on it, and they get marked as OBSOLETE if this one is OBSOLETE.