I am trying to write a syntax file for a log format. The log is line-based and comprises several parts in a specific order. It looks a bit like:
I, [timestamp #pid] INFO -- : [tagA] [tagB] some message
There can be zero, one, or several tags.
I have syntax items for each part. For example:
syn match fooProcessId '#\d\+' nextgroup=fooLevel skipwhite
syn match fooLevel '\<INFO\|DEBUG\>' nextgroup=fooSeparator skipwhite
It mostly works but I'm having trouble with the tags:
First, I don't want the timestamp and pid parts, which are enclosed in square brackets, to be matched as a tag.
Second, the message part of the line can itself contain things in square brackets (though not at its start) which should not be matched as tags.
My current approach (after many iterations!) is to not have fooTag
as a top-level item, but instead to have it contained in fooTail
which is everything after the separator (-- :
). fooTail
comprises zero or more tags and then the message (which does not contain tags).
syn match fooSeparator '-- : ' nextgroup=fooTail skipwhite
syn match fooTail '\(-- : \)\@<=.*$' contains=fooTag,fooMessage
syn match fooMessage '.*$' contained
syn match fooTag '\[.\{-}\]'hs=s+1,he=e-1 contained nextgroup=fooTag,fooMessage skipwhite
But this only matches the first tag.
At this point I'm losing track of what I have tried and feel I'm beginning to go round in circles. Any suggestions would be much appreciated!