[TxMt] Crazy idea: scope assertions in regular expressions

Ian Potter mcsticky at gmail.com
Sat Nov 24 16:09:49 UTC 2007


Just out of curiosity, where would you want the folding markers in  
your example? It looks like your regex will give you a start-folding- 
arrow at '=head2' and a stop-folding-arrow at '=cut' but it sounds  
like you want folds that start at each '=head' section and end at the  
following section. The problem is, a line can't be both a beginning  
and an ending. For example:

if (thing) {
	doStuff();
} else {
	doOtherStuff();
}

That will only give you one large folding section. You have to  
separate the second half from the first if you want two. You could  
also try to end each fold at the line before each '=head' section, but  
I don't know how you would go about that.

--
Ian Potter

On Nov 23, 2007, at 1:39 PM, Andy Armstrong wrote:

> I've just attempted to add folding for POD to TM's Perl language  
> definition - forgetting that I've already tried it previously. POD  
> looks like this:
>
> =head1 A heading
>
> =head2 A sub heading
>
> =cut
>
> The =cut always ends the POD. So my patterns look like ^=(?!cut) and  
> ^=cut\s*$ respectively. That doesn't work because the folding  
> mechanism expects a recursive syntax - each opening 'thing' requires  
> its own closing 'thing'.
>
> So I was thinking about how the problem could be solved and it  
> occurred to me that it'd be interesting to have an extension to  
> regular expression syntax that allowed an assertion to be made about  
> the matching scope.
>
> Assuming the assertion was called ?^ you could match the text 'foo'  
> only in storage.type.sub.perl or entity.name.function.perl with  
> something like this:
>
> (?^storage.type.sub.perl|entity.name.function.perl:foo)
>
> Generally (?^ <scope re> : <re> ) would allow <re> to match only if  
> the current scope name matched <scope re>.
>
> To solve my folding problem the code that scans for folds would have  
> to be scope aware - which may not be feasible architecturally.
>
> And I realise that extending RE semantics to grok rich text is a bit  
> of a big undertaking - but I thought it was a cute idea :)
>
> -- 
> Andy Armstrong, Hexten
>
>
>
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate




More information about the textmate mailing list