tags:

views:

46

answers:

1

I am creating a vim syntax file for a niche language that has no syntax file yet. The language has the following syntax when setting up a simple function.

foo(parameter)
    if parameter then
       print("yes")
    else
       print("no")
    end
 end

I want the end that is paired with the if to have the syntax coloring for conditionals and the "end" paired with the function declaration to have function syntax coloring. How do I achieve this? I currently have end set as a keyword. This ensures that it is colored, but it matches the color of the if only, never the function name.

Thanks for any help.

A: 

You'll need to define some syntax regions, starting with the if and ending with the end and another one starting with the function declaration and ending with the end. You can use the 'contains'/'containedin' options to allow nesting of regions etc. This is far from trivial, but there are lots of useful guides in :help syn-region among others. Read the whole help file thoroughly and experiment. To get you started, you could try something like this:

syn keyword MyLanguageElse else containedin=MyLanguageIfBlock

syn region MyLanguageIfBlock matchgroup=MyLanguageIf start="^\s*if\>" end="^\s*end\>" containedin=MyLanguageFuncBlock contains=MyLanguageIfBlock
syn region MyLanguageFuncBlock matchgroup=MyLanguageFunc start="^\s*\k*\ze(" end="^\s*end\>"

hi link MyLanguageIf Keyword
hi link MyLanguageElse Keyword
hi link MyLanguageFunc Comment

Good luck!

Al