3

gtksourceview で文字列を定義するために、次の短い XML スニペットを使用します。

<context id="string" style-ref="string" end-at-line-end="true">
    <start>"</start>
    <end>"</end>
    <include>
        <context id="special-string" style-ref="special">
            <match>(foo|bar)</match>
        </context>
        <context ref="def:line-continue"/>
    </include>
</context>

これにより、文字列内の「foo」または「bar」のインスタンスが強調表示されます。これら 2 つが文字列全体であるときに強調表示するとします。つまり、"foo" の中央の 3 文字が強調表示されますが、"foobar" はまったく強調表示されません。これは gtksourceview で可能ですか?

アンカー^...$と先読み/後読み(?<=")/を使用してみまし(?=")たが、前者は機能せず、後者は構文ハイライターを完全に壊しました。

4

1 に答える 1

3

サブコンテキストで親コンテキストの開始 (または終了) を一致させる方法がないようです。ただし、special-stringを最上位のコンテキストとして定義し、それをメイン言語コンテキストのstringの前に含めると、機能します。

<context id="special-string" style-ref="string">
    <match>"(foo|bar)"</match>
    <include>
        <context sub-pattern="1" style-ref="special"/>
    </include>
</context>

<context id="string" style-ref="string" end-at-line-end="true">
    <start>"</start>
    <end>"</end>
</context>
于 2016-01-12T10:03:14.050 に答える