Colin Hahn wrote:
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\)|$';
[...]
your problem is with that last line. the way it works now, if it encounters the literal text `% (fold)` then right after that other scopes will start matching again, as that ends the pattern. Instead, what you want is for the end pattern to be a lookahead on the % sign. So you should have:
end = '(?=%)|$'
or something similar. For more info, see the section of the TextMate manual about regular expression syntax.
-Jacob