[TxMt] Defining own language based on php + html? (2)

Andreas Pardeike andreas at pardeike.net
Tue Sep 12 15:12:11 UTC 2006


Additional question:

When I include another language, can I still "add" to that language?
I.e. my grammar looks like

{   scopeName = 'source.php+';
     patterns = ( { include = '#language'; } );
     repository =
     {    language = { patterns = (
                 {    include = '#part_html'; },
                 {    include = '#part_php'; },
             );
         };
         part_html = { patterns = (
                 {    name = 'meta.php+.html';
                     begin = '<htm>';
                     end = '</htm>';
                     patterns = (
                         {    include = '#part_php'; },
                         {    include = 'text.html.basic'; },
                         {    include = '$self'; },
                     );
                     contentName = 'text.html.basic';
                 }
             );
         };
         part_php = { patterns = (
                 {    name = 'meta.php+.php';
                     begin = '(?=<\?(?i:php|=)?)';
                     end = '(?<=\?>)';
                     patterns = (
                         {    include = '#part_html'; },
                         {    include = 'source.php'; },
                         {    include = '$self'; },
                     );
                     contentName = 'source.php';
                 }
             );
         };
     };
}

and the <htm>...</htm> part in

<?php
     include 'foo';
     <htm>
         <i>foo</i>
     </htm>
?>

is ignored. I thought it would match my part_html rule and become
a text.html.basic score and get parsed like that?

Andreas Pardeike



On 12 sep 2006, at 15.49, I wrote:

> I have the following meta language which uses the tags
> <php>...</php> and <htm>...</htm> to embed php and html.
>
> Now, I would like to write a custom language module that
> builds on the existing descriptions of php + html but I
> cannot get it to work due to the 2 level recursion that
> can occur.
>
> Here's an example that I would like to format:
>
> --------------------------------------
> <span value="prefix"/>
> <php>
>     print($foo);
>     <htm><span value="cool"/></htm>
> </php>
> <span value="foo"/>
> <php>
>     print($bar);
>     <htm>
>         <span value="test1"/>
>         <php> print($test); </php>
>         <span value="test2"/>
>     </htm>
>     print($extra);
> </php>
> <span value="suffix"/>
> --------------------------------------
>
> The outmost context is html and everything can be
> embedded in each other in many levels.
>
> Is this possible? I got close but i.e. I have problems
> using include "source.php" because it expects <?php as
> a start tag.



More information about the textmate mailing list