匹配gtksourceview中的整个字符串 [英] Matching entire string in gtksourceview

查看:148
本文介绍了匹配gtksourceview中的整个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此简短的XML代码段在gtksourceview中定义字符串:

Take this short XML snippet for defining strings in gtksourceview:

<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"的所有实例.假设我想在整个字符串中都突出显示这两个字符,以使"foo"的中间三个字符突出显示,而"foobar"则根本不突出显示.在gtksourceview中可以吗?

This highlights any instances of "foo" or "bar" inside a string. Suppose I want to highlight these two when they are the entire string, so that "foo" has the middle three characters highlighted but "foobar" is not highlighted at all. Is this possible in gtksourceview?

我尝试使用锚点^...$和lookahead/lookbehind (?<=")/(?="),但是前者无效,后者完全破坏了语法突出显示功能.

I tried using anchors ^...$ and lookahead/lookbehind (?<=") / (?=") but the former didn't work and the latter broke the syntax highlighter entirely.

推荐答案

似乎无法在子上下文中匹配父上下文的开头(或结尾).但是,如果将 special-string 定义为顶级上下文,并在主要语言上下文中将其包含在 string 之前,则它将起作用:

It seems like there is no way to match the beginning (or end) of the parent context in a subcontext. However, if you define special-string as a top-level context and include it before string in the main language context it will work:

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

这篇关于匹配gtksourceview中的整个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆