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
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
On Jan 5, 2007, at 4:41 AM, Jacob Rus wrote:
For more info, see the section of the TextMate manual about regular expression syntax.
The Language Grammars chapter in the TextMate book also has an example just like this:
http://www.pragmaticprogrammer.com/titles/textmate/index.html
James Edward Gray II