[SVN] Improving the Ruby Syntax
Chris Thomas
chris at cjack.com
Tue Mar 8 04:05:59 UTC 2005
On Mar 7, 2005, at 12:37 PM, Allan Odgaard wrote:
> And Eric, I actually have heredocs working in my current version :)
> Though the rule I had to make to match heredocts is a little special:
>
> name = "comments.heredoc.shell";
> begin = "(?=<<(\\w+))"; end = "^\\1";
> patterns = (
> { begin = "^<<\\w+"; end = "$";
> patterns = ( { include = "source.shell"; } );
> }
> );
>
> What it does is it makes the begin pattern only a look-ahead
> assertion on the delimiter. That way, the delimiter is not eaten when
> arriving at the sub-patterns, so I made one sub-pattern that also
> matches the delimiter with end set to end-of-line ($) and this rule
> has the entire shell syntax as sub-patterns, so basically, after the
> actual <<DELIMITER there will be normal shell-highlight till
> end-of-line.
So I'm curious, then. Could I do something like, for example:
/* HERE document containing Ruby code ("doc=<<END # mode Ruby") */
begin = "(?=<<(\\w+))\\s+#\\s*mode\\s+[Rr]uby"; end = "^\\1";
include = "source.ruby"
...
/* HERE document containing Python code ("doc=<<END # mode Python") */
begin = "(?=<<(\\w+))\\s+#\\s*mode\\s+[Pp]ython"; end = "^\\1";
include = "source.python"
...
... without causing major problems (like slowing down the highlighting
engine)?
> In practice this isn't perfect, and it still doesn't handle nested
> heredocs (actually it does, but in the reverse order), but I think
> this will cover 99% of the situations arising in code.
In any case, it's way more than any other editor I've ever seen can do.
Ship it. ;)
It's sounding really cool. Can't wait for b6!
Chris
More information about the textmate-dev
mailing list