I'm trying to put together a grammar and having a hard time getting the pattern matching right.

The line I'm interested in will be in the following format--

KW: [any text except a percentage sign can go in here] % (fold)

What I want to do is apply the scope comment.line.percentage from the % sign to the end of the line, and variable.notes to everything in between KW: and the percent sign.  I also want to be able to use Markdown-style italics within the variable.notes section.

Here is the patterns block as I have constructed it thus far:

patterns = (
{ name = 'comment.line.percentage';
match = '%.*$';
},
{ begin = '^KW:';
end = '% \(fold\)|$';
patterns = (
{ name = 'markup.italic.notes.variable';
match = '\*[^\*]+?\*';
},
);
contentName = 'variable.notes';
},
{ name = 'markup.italic.notes';
match = '\*[^\*]+?\*';
},
);

This does everything correctly except the % (fold) only acquires the scope of the whole grammar and not the comment scope.  Anything following a percentage sign on a line that doesn't begin with KW: is matched fine.

Any help on how to construct the grammar to match the end of this line would be appreciated!

Colin Hahn
»Geben Sie mir Kaffee, dann mache ich Phänomenologie daraus.«
"Give me my coffee so that I can make phenomenology out of it." -- Edmund Husserl