1

I'm writing a syntax highlighting file in gtksourceview for PARI/GP. There's one aspect that has me stuck: I want to highlight certain keywords only while inside another keyword. In particular, I want one kind of highlighting for "log" in

log(x)

(where log means the logarithm) and another in

default(log, 1)

(where log refers to log files). This seems like just what <context> was designed for, so I wrote

            <context id="default" style-ref="keyword">
                <start>default\s*(</start>
                <end>)</end>
                <include>
                    <context id="in-default" style-ref="defaults">
                        <keyword>log</keyword>
                        ...
                        <keyword>timer</keyword>
                    </context>
                </include>
                <context ref="string"/>
                <context ref="decimal"/>
                <context ref="float"/>
                <context ref="comment-multiline"/>
                <context id="meta-comment" style-ref="comment">
                    <match>\s*\(([^()]+)\)</match>
                </context>
            </context>

but this failed silently (gedit didn't syntax highlight at all). What did I do wrong? (Yes, I have defined the string, decimal, float, and comment-multiline contexts above.)

Charles
  • 11,269
  • 13
  • 67
  • 105
  • Note: I validated the XML with xmlstarlet, xmllint, and http://www.xmlvalidation.com/ so it's not a simple case of missing a closing tag or the like. If I remove the outer `` and `` it works file (but can't handle the distinction I mentioned). – Charles Dec 11 '15 at 19:59

1 Answers1

0

There were two problems: the inner contexts needed to be inside the <include> block, and the parentheses in <start> and <end> needed to be escaped.

Charles
  • 11,269
  • 13
  • 67
  • 105