1

I have a bug and I can't figure out the solution. Perhaps you esteemed folk can be of aid.

I want to extend a syntax file (julia syntax in polyglot package). I want to include the following patterns

"\::\zs\w*\ze"
"\^\s*function \zs\w*\ze\("

The first is intended to match words following ::. The second is intended to match the function name foo in an expression like

function foo(bar)

In my .vim/after/syntax/julia.vim, I write

syntax match juliaCustomType "\v::\zs\w*\ze" display
syntax match juliaFunctionName "\v^\s*function \zs.*\ze\(" display

highlight def link juliaCustomType Constant
highlight def link juliaFunctionName Function

And this works if I disable vim-polyglot and the julia-vim packages, the ones providing julia syntax support. If I add either of them back, it no longer works.

I add both the custom groups to the relevant syntax cluster juliaExpressions, which is the one that is allowed to be contained in other regions everywhere. I check this by making a mock syn match like this syntax match juliaCustomType "foobar" and see that it highlights inside syntax regions.

Now if I remove \zs and \ze from the ::matching, it works but highlights the :: which I don't want. The second expression, I believe has some problems because of how function is handled in this line from the package syntax file:

let s:nodot = '\%(\.\)\@'.s:d(1).'1<!'
exec 'syntax region juliaFunctionBlock matchgroup=juliaBlKeyword start="'.s:nodot.'\<function\>" end="'.s:nodot.'\<end\>" contains=@juliaExpressions fold'

But I can't for the life of me figure out what the problem is. Any help or suggestions are welcome!

  • Try the following: Replace all double quotes (") in the syntax match lines with single quotes ('). – Ralf Apr 12 at 12:19
  • Thanks for the tip. It didn't work immediately, but I'll try more iterations similar tries to see if the encapsulation could be the problem. That hadn't really been considered yet! – donk Apr 13 at 13:31
  • Read help on “string” and “literal-string” – Ralf Apr 13 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.