gtksourceview: handling multiple languages



I use gtksourceview in my application's script editor and find it very useful -- many thanks to the developers! Right now I'm trying to do something a bit more ambitious than what I've attempted to date, and I'd appreciate some advice.

The econometrics program I work on, gretl, supports embedding of "foreign" scripts, with a mechanism to shuttle data and results between gretl and the foreign program (which might be, e.g., python, R, or octave). The set-up looks like this (taking R as an example):

<initial gretl statements>
foreign language=R [ --send-data ]
  <R statements>
end foreign
<more gretl statements>

The issue, then, is switching from "native gretl" syntax highlighting in the main script, to appropriate highlighting for the statements inside the "foreign" block, and then back to native gretl when the block ends.

I gather that gtksourceview can handle this, and I'm using the treatment of javascript inside html (in html.lang) as a template. Here's my attempt at the relevant gtksourceview stanza (for R in particular, though it would be nice to be able to generalize it) in my gretl.lang file:

<context id="foreign-R" class="no-spell-check" style-inside="true">
  <start>^\s*foreign\s+language=R.*</start>
  <end>^\s*end\s+foreign</end>

  <include>
    <context id="R-code" extend-parent="false">
      <start>^</start>
      <include>
        <context ref="r:r"/>
     </include>
    </context>
  </include>
</context>

This works partially: it switches to R highlighting within the block OK, but (a) it leaves the "foreign..." and "end foreign" lines unhighlighted (I want them to be highlighted since both "foreign" and "end" are gretl keywords) and (b) the R-style highlighting bleeds over the end of the "foreign" block and affects everything from that point on in the main gretl script.

I suppose I'm missing something fairly basic here. Any suggestions? I can provide more detail on the gretl.lang file, but the basic version (prior to my attempt to handle "foreign" properly) can be found at

http://users.wfu.edu/cottrell/gretl/gretl.lang

--
Allin Cottrell
Department of Economics
Wake Forest University


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]