2

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!

1 Answer 1

0

The answer is to remove fooMessage from fooTag's nextgroup:

syn match fooTag       '\[.\{-}\]'hs=s+1,he=e-1  contained nextgroup=fooTag

Although I understand why this works I don't understand why it didn't work before. Initially I guessed it was last-one-wins, so I reversed the order of the groups in nextgroup...but it gave the same result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.