Search code examples
gtksyntax-highlightinggeditgtksourceviewpari-gp

Embedding keywords in other keywords: context in gtksourceview


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.)


Solution

  • 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.