Hi,
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.
Is this *very* complicated? Andreas Pardeike
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.
On 12/9/2006, at 17:12, Andreas Pardeike wrote:
Additional question:
When I include another language, can I still "add" to that language? [...]
<?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?
Normally, yes -- but because the PHP grammar matches the <?php tag, and enters a new context after this tag, it will not see the other rules you include (as these are only in the parent context of the <? php match) -- the match for <?php you do in your new grammar is a look-ahead match, meaning that this itself does not “eat” the construct, and thus leaves it for the PHP grammar.
Again this is a problem with having the PHP grammar match <?php … ?> itself.
I’d suggest you clone the PHP grammar, remove the matching of <?php … ?> from this clone, and then include that instead of the stock PHP grammar -- long-term there will be more flexible solutions for augmenting language grammars.
On 12/9/2006, at 15:49, Andreas Pardeike wrote:
[...] Is this possible? I got close but i.e. I have problems using include "source.php" because it expects <?php as a start tag.
This is a bit ironic, because for the last (almost) two years, the PHP grammar did not include the match for <?php, as I wanted it as a “raw” PHP grammar — but public pressure made me change it…
I am afraid that there is no way that the PHP grammar can now be reused (included) in another grammar which does not have the PHP code inside <?php … ?> blocks :/