[TxMt] Re: Matching multiple lines in a grammar pattern

Nate Cavanaugh nate at shift22.com
Sat Aug 9 22:31:50 UTC 2008


Hi Michael,
It took me a while to find the exact way to do this, but I got it, and it's
almost 100% perfect.

The only thing I didn't cover for was when there are extra lines at the
beginning and end of the document.

I don't think there is a way to check those, and perhaps it's more effort
than it's worth. I think I may just write a command that hooks into the save
functionality that just chops all empty lines from the top and bottom of the
file, so that it automatically just trims it. I'll play around with it.

Thanks for your help Michael!

If anyone is interested, here is the grammar rule I ended up going with:

patterns = (
		{	name = 'meta.extra-lines.js';
			comment = 'match all extraneous lines';
			begin = '^\n';
			end = '^.';
			patterns = (
				{	name = 'invalid.extra-lines.js';
					match = '^\n';
				},
			);
		},


Michael Sheets-2 wrote:
> 
> On Aug 8, 2008, at 7:53 PM, Nate Cavanaugh wrote:
> 
>> I'm trying to add an invalid scope to a certain group of lines.  
>> Basically,
>> the regex pattern I would like to match is this:
>>
>> ^(\n){2,}
> 
> No match can be more than one line, no way to get around that.
> 
> A solution to your issue though…
> 
> Match one empty line with a begin, then include a rule in there to  
> match empty lines and mark them invalid. Then end on any non-empty  
> line, should work fine.
> 
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
> 
> 

-- 
View this message in context: http://www.nabble.com/Matching-multiple-lines-in-a-grammar-pattern-tp18901103p18909083.html
Sent from the textmate users mailing list archive at Nabble.com.




More information about the textmate mailing list