syntax coloring regexp

0 views
Skip to first unread message

acarcha...@gmail.com

unread,
Dec 19, 2008, 2:27:14 AM12/19/08
to vim_use

I am trying to create a syntax file and I am having trouble in marking
out a comment region. The comment starts with an asterisk with the
first non white space character preceding it (including newlines) a
semi-colon. The comment ends with a semi colon.

For example everything between (and including) the asterisk and the
semi colon is a comment:
;

*safagdgghgh;


In contrast, in the following case the asterisk and the semi-colon do
not enclose a comment since the first non white space character
preceding the asterisk is not a semi-colon

1234*abcd;


The contents of my syntax file:

syn case ignore

syn region tComment start=";\_s*\zs\*" end="\;"

hi tComment term=bold cterm=NONE ctermfg=Red ctermbg=Black
gui=NONE guifg=Red guibg=White
syn sync fromstart


With the above, the following line gets colored correctly:
; *adsafasff;

with everything between the asterisk and the semi-colon colored red.

However, it cannot deal with line breaks, and the following text
remains unchanged:

;

*adsafasff;


The regexp starting the comment appears to be finding the right
pattern..

Is there any way I can handle line breaks?

TIA,

Tony Mechelynck

unread,
Dec 19, 2008, 8:17:01 AM12/19/08
to vim...@googlegroups.com

What about (untested)

syn match tComment /;\_s*\zs\*.\_{-};/
hi link default tComment Comment

? (You may want to set ":syn sync" to a large-enough "minlines" value.


Best regards,
Tony.
--
Plato, by the way, wanted to banish all poets from his proposed Utopia
because they were liars. The truth was that Plato knew philosophers
couldn't compete successfully with poets.
-- Kilgore Trout (Philip J. Farmer) "Venus on the Half
Shell"

Ben Schmidt

unread,
Dec 19, 2008, 7:29:55 PM12/19/08
to vim...@googlegroups.com
[...]

> syn region tComment start=";\_s*\zs\*" end="\;"
[...]

> With the above, the following line gets colored correctly:
> ; *adsafasff;
>
> with everything between the asterisk and the semi-colon colored red.
>
> However, it cannot deal with line breaks, and the following text
> remains unchanged:
>
> ;
>
> *adsafasff;
>
> The regexp starting the comment appears to be finding the right
> pattern.
>
> Is there any way I can handle line breaks?

I'm not sure why it doesn't work...but I suggest trying using \@<=
instead of \zs as my experience has been that this often works better,
particularly in syntax highlighting; must be something to do with the
way the pattern engine works. So...try something like this:

syn region tComment start="\(;\_s*\)\@<=\*" end=";"

(You don't need a backslash before a semicolon like you had in the end
pattern really, do you? I don't think so, but I could be going crazy...)

Ben.

acarcha...@gmail.com

unread,
Dec 20, 2008, 12:50:57 PM12/20/08
to vim_use

In my ignorance I filed a bug report, Bram pointed out that this
restriction in mentioned in :help syn-multi-line, the \zs causes the
problem above.
Reply all
Reply to author
Forward
0 new messages