[TxMt] Help with RegEx in Bundles
Edmundo Ortega
ed at westernfreight.com
Thu Jun 16 23:42:10 UTC 2005
Thanks a lot Allen, I'm learning a LOT about regex today. The problem
I'm running into now is that while the captures work, they don't
allow color coding to continue on to the non-captured items.
So if my function is like this:
public function addItem(name: String, item: MenuItem): Void {
Then I want my other color coding rules to properly color "String"
and "MenuItem". But it seems as these are left as source code. I
assume it's because this string has already been processed and it
would take innumerable multiple passes to make it work as I wish.
Unless I'm missing another important aspect of the coloring
functionality. Thanks again!
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