在VIM的 "syntax region" 语法中,支持一个特殊的 "keepend" 参数。 在 VIM 的介绍中, 对 keepend 用法的介绍是通过一个行内注释,以及可以在注释内出现的语法来讲解的。因此我已开始对 keepend 的用法也产生了错觉,认为它就是用来匹配行尾 "$" 的。但是实际上,这样的认识是完全错误的。
Let's take a look at this example.
syntax region xDocLink start="{" end="}" contained
syntax region xDocComment start="/\*\*" end="\*/"
\ contains=xDocLink
syntax region xBlock start="{" end="}"
\ contains=xDocComment keepend
if the "keepend" is defined in xBlock, the follows messge will be highlighted in wrong way.
{
/**
* The comments {@links}
*/
Block;
}
The xBlock will be terminated at the "}" inside the xDocComment. Even the the first "{" are matched as xDocLink, the "}" is still consided as the end of xBlock. It is the side effect of "keepend" instruction of xBlock.
The really meanings of "keepend" is to match the end of region, even it has already matched with its nested regions, whatever what's the pattern of end, in most case, it is "$", but it can be anything there.
其实 "keepend" 语句的实际意义是:尽可能匹配 region 所指定的 end pattern, 即便 这个pattern实际上已经被它的内联region所匹配了。这里的 keepend 实际上是指 end pattern,而不管这个 pattern 到底是什么,尽管大多数时候它都是 "$"。
没有评论:
发表评论