Hi all, 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,}
Which works fine in the Find dialog, but when trying to use it as a pattern, it doesn't work. I am guessing because of the way that the pattern matching works for grammars, but is there a way to match this?
The logic is, I would like to match every line that has no content on it, but is part of a group of 2 or more extraneous lines. One \n is valid, but 2 or more is invalid.
I've tried so many variations of trying to use captures, matching content, but it seems to be treating each line as it's own match independent of the previous or next ones.
Anyone know how I might go about applying this?
Any help is greatly appreciated.
Thanks!
From what I can grok of the ANTLR Book, I don't think either ^ as
start-of-line or {n,m} for specifying number of repetitions are allowed.
Have you tried:
EXTRA_NEWLINES : '\n' '\n'+;
- Chris
On Fri, Aug 8, 2008 at 5:53 PM, Nate Cavanaugh nate@shift22.com wrote:
Hi all, 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,}
Which works fine in the Find dialog, but when trying to use it as a pattern, it doesn't work. I am guessing because of the way that the pattern matching works for grammars, but is there a way to match this?
The logic is, I would like to match every line that has no content on it, but is part of a group of 2 or more extraneous lines. One \n is valid, but 2 or more is invalid.
I've tried so many variations of trying to use captures, matching content, but it seems to be treating each line as it's own match independent of the previous or next ones.
Anyone know how I might go about applying this?
Any help is greatly appreciated.
Thanks!
View this message in context: http://www.nabble.com/Matching-multiple-lines-in-a-grammar-pattern-tp1890110... Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Hi Chris, Thanks for your prompt reply. I do have to apologize though, as I wasn't quite sure what you meant in your response.
I've never heard of ANTLR, is it the engine that parses the grammars?
But I will say that when I use the ^ and {n, m} in other patterns for the grammar, it does work, just not for multiple lines.
The line you sent over doesn't work for me in the grammar section of the bundle, but perhaps you meant to paste it somewhere else?
Here is what I have so far: patterns = ( { name = 'invalid.extra-lines.js'; comment = 'match all extraneous lines'; begin = '^(\n)'; end = ''; },
Thanks again :)
Chris Rebert wrote:
From what I can grok of the ANTLR Book, I don't think either ^ as start-of-line or {n,m} for specifying number of repetitions are allowed.
Have you tried:
EXTRA_NEWLINES : '\n' '\n'+;
- Chris
On Fri, Aug 8, 2008 at 5:53 PM, Nate Cavanaugh nate@shift22.com wrote:
Hi all, 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,}
Which works fine in the Find dialog, but when trying to use it as a pattern, it doesn't work. I am guessing because of the way that the pattern matching works for grammars, but is there a way to match this?
The logic is, I would like to match every line that has no content on it, but is part of a group of 2 or more extraneous lines. One \n is valid, but 2 or more is invalid.
I've tried so many variations of trying to use captures, matching content, but it seems to be treating each line as it's own match independent of the previous or next ones.
Anyone know how I might go about applying this?
Any help is greatly appreciated.
Thanks!
View this message in context: http://www.nabble.com/Matching-multiple-lines-in-a-grammar-pattern-tp1890110... Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Sorry, I'm subscribed to both the ANTLR mailing list and this one and got the two mixed up. Apologies for the confusion!
- Chris
On Fri, Aug 8, 2008 at 8:59 PM, Nate Cavanaugh nate@shift22.com wrote:
Hi Chris, Thanks for your prompt reply. I do have to apologize though, as I wasn't quite sure what you meant in your response.
I've never heard of ANTLR, is it the engine that parses the grammars?
But I will say that when I use the ^ and {n, m} in other patterns for the grammar, it does work, just not for multiple lines.
The line you sent over doesn't work for me in the grammar section of the bundle, but perhaps you meant to paste it somewhere else?
Here is what I have so far: patterns = ( { name = 'invalid.extra-lines.js'; comment = 'match all extraneous lines'; begin = '^(\n)'; end = ''; },
Thanks again :)
Chris Rebert wrote:
From what I can grok of the ANTLR Book, I don't think either ^ as start-of-line or {n,m} for specifying number of repetitions are allowed.
Have you tried:
EXTRA_NEWLINES : '\n' '\n'+;
- Chris
On Fri, Aug 8, 2008 at 5:53 PM, Nate Cavanaugh nate@shift22.com wrote:
Hi all, 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,}
Which works fine in the Find dialog, but when trying to use it as a pattern, it doesn't work. I am guessing because of the way that the pattern matching works for grammars, but is there a way to match this?
The logic is, I would like to match every line that has no content on it, but is part of a group of 2 or more extraneous lines. One \n is valid, but 2 or more is invalid.
I've tried so many variations of trying to use captures, matching content, but it seems to be treating each line as it's own match independent of the previous or next ones.
Anyone know how I might go about applying this?
Any help is greatly appreciated.
Thanks!
View this message in context: http://www.nabble.com/Matching-multiple-lines-in-a-grammar-pattern-tp1890110... Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@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-tp1890110... Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
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.
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@lists.macromates.com http://lists.macromates.com/listinfo/textmate