Saturday, September 25, 2010

Re: Help with syntax defintion

On Fri, 24 Sep 2010, Dewdman42 wrote:

> I'm trying to create a syntax definition. I need to catch the
> following occurrences in a file
>
> Groove <name> <comments with spaces>
>
> Groove is the keyword, the <name> can be any single word with any
> characters other than "/" and the comment is the rest of the text on
> the line after that.
>
> I would like to assign a color to "Groove" (easy) and a color to the
> comments, and then either leave the <name> unhighlighted or also
> assign a color to it.
>
> I have tried all manner of contains, contained, nextgroup, etc..and I
> can't seem to find a way to handle this situation, but I'm new to
> this, so maybe I am missing something obvious.
>
> Can anyone help?
>
> This is the last thing I tried:
>
> syn keyword MMAgroove groove nextgroup=MMAid skipwhite
> syn match MMAid "[^\s/]+" transparent
> contains=MMAgrooveComment
> syn match MMAgrooveComment ".*$" contained
>

This works for the following example:

groove some-id the rest is the groove comment

syn region MMAgrooveComment matchgroup=MMAgroove start=/^groove\ze\s/ end=/$/ contains=MMAid
syn match MMAid "\%(^groove\s\+\)\@<=\zs[^[:space:]/]\+" contained

" some colors for testing
" helped point out that the whole file was matched as MMAid
hi def link MMAgroove Keyword
hi def link MMAid Identifier
hi def link MMAgrooveComment Comment


I tend in general to shy away from 'syn keyword', because it's not
usually what you want. (If 'groove' were a keyword, the second 'groove'
on the line would be highlighted.)

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment