Hi,
The project I am currently working on requires me to write xml configuration files for a custom application for experience sampling. The files contain embedded python scripts, contained in the following regions:
<script event="OnLoad"> <![CDATA[ python script ]]> </script>
I know that TextMate is able to deal with embedded regions that have a different language deffinition than the main file (like php and javascript sections in HTML) so I was trying to set this up for XML so I can have proper syntax highlighting for python. So far, though, I have not had any luck with this. I tried adding the following in the xml language definition, both right after the section for embedded java and, when that didn't work, right after the section for CDATA comments, but it doesn't seem to work:
{ name = 'source.python.embedded.xml'; begin = '<script.*?}>\s*?<![CDATA['; end = ']]>\s*?<script/>'; beginCaptures = { 0 = { name = 'punctuation.section.embedded.begin.xml'; }; }; endCaptures = { 0 = { name = 'punctuation.section.embedded.end.xml'; }; }; patterns = ( { include = 'source.python'; } ); },
This was based on the example for embedded java, but obviously I either didn't understand what the java example does, or I didn't specify the begin and end strings correctly. I also suspect that since there is already a definition for CDATA comments, this needs to be in a specific place to override that definition.
Any help with getting this to work would be greatly appreciated. The scripts can be quite long, so having proper syntax highlighting would make things much easier.
Thanks so much, Pedja
On 15 Jun 2008, at 01:25, Pedja wrote:
[...] I was trying to set this up for XML so I can have proper syntax highlighting for python. So far, though, I have not had any luck with this. I tried adding the following in the xml language definition, both right after the section for embedded java and, when that didn't work, right after the section for CDATA comments, but it doesn't seem to work:
Adding _after_ the more general rule e.g. for CDATA, when you match CDATA, is not going to work. It is the first rule in the grammar which matches a construct, which wins.
{ name = 'source.python.embedded.xml'; begin = '<script.*?}>\s*?<![CDATA['; end = ']]>\s*?<script/>'; beginCaptures = { 0 = { name = 'punctuation.section.embedded.begin.xml'; }; }; endCaptures = { 0 = { name = 'punctuation.section.embedded.end.xml'; }; }; patterns = ( { include = 'source.python'; } ); },
The patterns are single-line matches. Your script + CDATA is split over two lines, so you will have to change strategy to match this, i.e. write an outer rule to match <script> with an inner rule to match CDATA (if necessary).