[TxMt] Help with RegEx in Bundles

Edmundo Ortega ed at westernfreight.com
Thu Jun 16 23:47:01 UTC 2005


Doh. Never mind. I just stopped trying to color the parentheses and  
now it works as I wish. Now, from this string:

public function addItem(name: String, item: MenuItem): Void {

I'm only capturing:

function addItem

And I'm leaving the coloring of the parenthesis and the rest of the  
string to the other rules.



On Jun 16, 2005, at 10:40 AM, Allan Odgaard wrote:

> On Jun 16, 2005, at 19:25, Edmundo Ortega wrote:
>
>
>> I want to color: "addItem(" and ")" but not "name: String, item:  
>> MenuItem
>>
>> Is this possible in one regex expression?
>>
>
> Yes, assuming you're using 1.1b12 you can name the captures, this  
> is done like this:
>     match = "(\\b(function)\\s+()[a-zA-Z_]\\w*)\\s*\\([^\\)]*(\\))";
>     captures = {
>         1 = { name = "storage.type"; };
>         3 = { name = "storage.type"; };
>     };
>
> That way capture #1 and #3 gets “storage.type” as the name.
>
>
>> Is there some way to match something by looking for a leading (or  
>> trailing) indicator without including the indicator in the match?
>>
>
> You can both use look-ahead and look-behind assertions in the  
> regular expression.
>
> E.g.: match = "foo(?=bar); or
>       match = "(?<=foo)bar;
>
> The first one matches foo, when followed by bar. The second matches  
> bar, when preceded by foo.
>
>
>> I'm currently using this regex to successfully capture the whole  
>> thing:
>> match = "\\b(function)\\s+([a-zA-Z_]\\w*)\\s*\\([^\\)]*\\)";
>>
>
> Another approach is to use begin/end matches. E.g.:
>     begin = "\\b(function)\\s+([a-zA-Z_]\\w*)\\s*\\(";
>     end = "\\)";
>
> You'd still need to put a capture around these patterns and name  
> that capture (to get a name associated only to these two things),  
> but it allows you to provide a new set of rules for the stuff  
> between the begin/end patterns using e.g.:
>     patterns = (
>         { name = "support.class"; match = "\\b(String|MenuItem|...)\ 
> \b"; },
>         ...
>     );
>
> ______________________________________________________________________
> 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