使用这个简短的 XML 片段在 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 中可能吗?
我尝试使用锚点^...$
和前瞻/后瞻(?<=")
/ (?=")
但前者不起作用,后者完全破坏了语法荧光笔。
似乎无法匹配子上下文中父上下文的开头(或结尾)。但是,如果您定义特殊字符串作为顶级上下文并在之前包含它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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)