我有一个语法文件,用于突出显示嵌入在bash脚本中的awk:
syn include @AWKScript syntax/awk.vim
syn region AWKScriptCode matchgroup=AWKCommand
\ start=+[=\\]\@<!'+ skip=+\\'+ end=+'+ contains @AWKScript contained
syn region AWKScriptEmbedded matchgroup=AWKCommand
\ start=+\<\(g\?awk\|\$AWK\)\>+ skip=+\\$+ end=+[=\\]\@<!'+me=e-1
\ contains=@shIdList,@shExprList2 nextgroup=AWKScriptCode
syn cluster shCommandSubList add=AWKScriptEmbedded
hi def link AWKCommand Type
问题在于此部分:
start=+\<\(g\?awk\|\$AWK\)\>+
它适用于awk和gawk,但不适用于$ AWK。如何添加规则以匹配$ AWK作为AWKScriptEmbedded区域的起始模式?
答案 0 :(得分:2)
问题是$AWK
语法组已突出显示shDerefSimple
,因此未应用新区域。将语法定义拆分为两部分,并为后者添加containedin=
:
syn region AWKScriptEmbedded matchgroup=AWKCommand
\ start=+\<g\?awk\>+ skip=+\\$+ end=+[=\\]\@<!'+me=e-1
\ contains=@shIdList,@shExprList2 nextgroup=AWKScriptCode
syn region AWKScriptEmbedded matchgroup=AWKCommand
\ start=+\$AWK\>+ skip=+\\$+ end=+[=\\]\@<!'+me=e-1
\ contains=@shIdList,@shExprList2 containedin=shDerefSimple nextgroup=AWKScriptCode