I am trying to highlight a custom language in TextMate. However, the following definition does not highlight PHP insertions (I do select it for my *.serpent files):
{ scopeName = 'source.serpent';
fileTypes = ( 'serpent' );
patterns = (
{ begin = '<\?';
end = '\?>';
patterns = ( { include = 'source.php'; } );
},
);
}
If I select PHP language, then the PHP parts are highlighted.
What can be the reason? Should it work?
I was also considering ruby insertions with <% %> delimiters, but it doesn't work with the simplest setup.
Update
Apparently, it is an issue of PHP only. The following language definition highlights Ruby and Serpent languages in my text, but not P开发者_如何学JAVAHP insertions! What is wrong here?
{ scopeName = 'source.phpruby.serpent';
fileTypes = ( 'serpent', 'serpent.php', 'serpent.erb' );
patterns = (
{ begin = '<\?(php|=)?';
end = '\?>';
patterns = ( { include = 'source.php'; } );
},
{ begin = '<%';
end = '%>';
patterns = ( { include = 'source.ruby'; } );
},
{ include = 'source.serpent'; },
);
}
I have made it working by replacing source.php with #language in my patterns and by copying the repository from PHP language.
On Fri, Jul 9, 2010 at 08:02, Allan Odgaard wrote:
We made the PHP grammar itself match the construct, so with your grammar, those bits have been consumed by the including grammar, and the included PHP grammar will therefor be a no-op.
The reason we made it this way was so that the PHP grammar can sort of work when used as the root grammar, since lots of users insist on using it that way, despite our efforts¹ to educate ;)
¹ http://wiki.macromates.com/Troubleshooting/PHPSyntaxHighlight
With the help of the God, I understood my mistake and was able to make a working (at least highlighting!) definition:
{ scopeName = 'source.phpruby.serpent';
fileTypes = ( 'serpent', 'serpent.php', 'serpent.erb' );
patterns = (
{ begin = '<\?(php|=|)';
end = '\?>';
include = 'source.php';
},
{ begin = '<%';
end = '%>';
patterns = ( { include = 'source.ruby'; } );
},
{ include = 'source.serpent'; },
);
}
精彩评论