GNOME Bugzilla – Bug 708113
Inconsistent Word Boundary Detection using <keyword-char-class>
Last modified: 2013-09-24 16:13:52 UTC
Custom word boundary detection using 'keyword-char-class' is not consistent between leading and trailing word boundaries. This behaviour can be shown using the following gedit language definition file: <?xml version="1.0" encoding="UTF-8"?> <language id="test" _name="Test" version="2.0" _section="Sources"> <metadata> <property name="globs">*.tst</property> </metadata> <styles> <style id="keyword" _name="Keyword" map-to="def:keyword"/> </styles> <keyword-char-class>[A-Za-z0-9_]</keyword-char-class> <definitions> <context id="test-keyword" style-ref="keyword"> <keyword>helloworld</keyword> </context> <context id="test"> <include> <context ref="test-keyword"/> </include> </context> </definitions> </language> A test text file, e.g. highlight.tst, illustrates the behaviour as described by the comments: helloworldX # The keyword 'helloworld' isn't highlighted which is correct. Xhelloworld # The keyword 'helloworld' is highlighted which is *incorrect*. helloworld$ # The keyword 'helloworld' is highlighted which is correct. $helloworld # The keyword 'helloworld' is highlighted which is correct.
Created attachment 254975 [details] [review] Patch for negative lookbehind regex for <keyword-char-class>.
The negative lookbehind regex used by 'keyword-char-class' should begin with '?<!' instead of '?!<'. The attached patch file fixes this issue. As a workaround an equivalent regular expression could be defined for existing versions of gtksourceview: [SNIP] <define-regex id="my-regex">[A-Za-z0-9_]</define-regex> <define-regex id="my-word-boundary">((?<!\%{my-regex})(?=\%{my-regex}))|((?<=\%{my-regex})(?!\%{my-regex}))</define-regex> <context id="test-keyword" style-ref="keyword"> <prefix>\%{my-word-boundary}</prefix> <suffix>\%{my-word-boundary}</suffix> <keyword>helloworld</keyword> </context> [SNIP]
Thank you for the patch. Indeed, from the GLib doc: https://developer.gnome.org/glib/stable/glib-regex-syntax.html > Lookbehind assertions > > Lookbehind assertions start with (?<= for positive assertions and (?<! for > negative assertions. So I'll push your patch after the freeze (see https://wiki.gnome.org/ThreePointNine ).
Review of attachment 254975 [details] [review]: commit_after_freeze
Commit pushed to the master branch. It will be available for GtkSourceView 3.10.1.