# [TxMt] Syntax Highlight Question

Allan Odgaard allan at macromates.com
Wed Dec 8 00:04:17 UTC 2004

On Dec 6, 2004, at 19:22, Jeroen van der Ham wrote:

> [...] The thing I want to do is something like:
> - match commands (begin with '\' followed by a word
> - this can be followed by [\w+]
> - and this can be followed by {.*}
>
> And what I would like to do is apply the global patterns to the '.*'
> mentioned above, and if nothing global matches, then apply a color.

Yes, that requires recursion in the rules which is not supported at
present time (but will be a 1.1 thing). You can make the inner rule
match nested braces though, something like:
\{[^{}]*(?R)?[^{}]*\}

This will match a sequence of properly nested braces from the starting
brace to the matching ending brace. E.g. for the string:
\foo{\bar{\fud{...}}} \other

It will match this portion:
{\bar{\fud{...}}}

But be careful with the (?R) construct, it currently doesn't check for
infinite recursions (which include left-recursions).

> PS. I seem to remember something about using groups to define
> different colors in a pattern, but I forgot how that works. Can anyone
> tell me how that works and/or add that to the wiki ? :)

This is from Help -> Syntax Highlight:

Additionally you can append [n] to any of the keys which
set the color or font style, to only make the color/font
style affect the nth regular expression capture. When
you add this suffix, you must quote the key, if you use
the ASCII property list format.

For example, if we want to match @selector, but only
want to underline the word part, we could make a rule
like this:
(
match = "@(selector)"; "fontStyle[1]" = ( underline );
)