2

I do most of my coding in gedit, which highlights integers and other syntax. When I use an integer range in Ruby, represented as 0..3 for example, the integers are not properly highlighted and are instead the normal text colour. I checked out /usr/share/gtksourceview3.0/language-specs/ruby.lang, but, alas, the solution appears to be much more complicated than I had anticipated. How can I fix this problem?

1 Answer 1

2

Well, right now I may suggest only 'brute force' solution. This task is all about knowing regular expressions.

Here it is.

First of all I decided to define a new regular expression that will match the whole range, instead of redefining decimal, but uses the same styles. There are 3 steps.

By the way, this is a guide about language spec for gedit.

Styles

Let's define styles first.

In section <styles> insert before decimal:

<style id="range" _name="Range" map-to="def:decimal"/>

Matching

Then in section <definitions> insert before decimal:

<context id="range" style-ref="decimal">
  <match>(?&lt;![\w\.])(([1-9](_?[0-9])*|0)\s*\.\.\.?\s*([1-9](_?[0-9])*|0))(?![\w\.])</match>
</context>

This regular expression matches decimal only ranges (there is always room for improvement) such as

3..7
3...7
3 .. 7
3 ... 7

All the used regular expressions are PCRE (Perl compatible). The best to my mind way would be skimming through Perl Regular Exressions Doc. So you may invent your own and match whatever you want.

Invoke matching

To force syntax highlighting use this expression we must put it before decimal in the section <include>:

<context id="ruby" class="no-spell-check">
  <include>
    ...
    <context ref="range"/>
    <context ref="decimal"/>
    ...
  </include>
</context>

And restart Gedit!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .