0

I am trying to make an angularjs syntax highlighting file for vim. A piece of the file is:

syn match ngMethods                /\.[0-9A-Za-z_\-\$]\+\s*\((\|=\)/ contains=AngularMethods
syn keyword AngularMethods         contained $addControl $anchorScroll $animate ...

syn match ngObjMethods             /^\s*[0-9A-Za-z_\-\$]\+\s*:/ contains=AngularObjectMethods
syn keyword AngularObjectMethods   contained compile controller link ...

etc...

Down below I have:

hi def link AngularMethods       Function

hi def link AngularObjectMethods Function

The first regular expression (for AngularMethods) is supposed to capture things like $addControl in the following:

myelement.$addControl()
myelement.$addControl = function ()

The second regular expression (for AngularObjectMethods) captures things like compile in:

    compile : function () {}

The AngularMethods one does NOT work but the latter one does. Can anyone see the problem? I've also tried using the regexes:

/\.\zs[0-9A-Za-z_\-\$]\+\ze\s*\((\|=\)/

/\.[0-9A-Za-z_\-\$]\+\s*\((\|=\)\@=/

The former matches the exact word. The latter is something I saw in another syntax file. Any ideas? Thanks for your help!

Edit:

Kent (below) was correct about the keyword. This uncovered the real problem which is that I have another regex:

syn match ngProperties          /\.[0-9A-Za-z_\-\$]\+\s*[^(=]/ contains=AngularProperties
syn keyword AngularProperties   contained $attr $dirty $error ...

which is supposed to be the complement of the ngMethods regex. If I comment out the ngProperties regex, the ngMethods regex works. This means ngProperties is bad. It is supposed to catch things like $attr in:

var myAttribute = element.$attr;

I will try to fix this. Can someone post the correct regex just in case?

4

1 回答 1

2

正则表达式不是您的语法的问题。

问题的原因很可能是,您的选项iskeyword没有美元 ( $) 符号。

你可以测试的是:

  • 删除$from contained $addControl $anchorScrol,看看它是否会工作

或者

  • 执行:set iskeyword+=$看看它是否有效。
于 2013-09-03T09:16:00.303 回答