php heredoc?

1 view
Skip to first unread message

steen...@hotmail.com

unread,
Jul 7, 2008, 9:55:02 AM7/7/08
to GOLD Parsing System
Hi,

I’ am wondering if there is a solution to parsing the php heredoc
statement.

<?php
echo <<<BEGIN
html code
BEGIN;
?>

Greeting,
Bas

Dave Dolan

unread,
Jul 7, 2008, 4:39:01 PM7/7/08
to gold-pars...@googlegroups.com
two parsers.  You're parsing two languages there, they just happen to appear on the same page.  You can have a 'mini-lexer' that strips out sections of PHP, sections of HTML, and even sections of HTML neseted in Heredocs, then you have to parse each individually.

Gold gets you a parser, what it doesn't get you is a single parser for tasks that require more than one ;)  This is the trouble with all good frameworks. They abstract the hard work to the point where people expect everything you do from then on to be as simple.
--
---------------------------------------------------------------
Dave Dolan
Certified Computer Geek-inator
http://davedolan.com
dave....@gmail.com

steen...@hotmail.com

unread,
Jul 8, 2008, 3:34:30 AM7/8/08
to GOLD Parsing System
Hi,

The problem is that a heredoc statement
has a variable name, like in the example i gave it has the name
“begin”
But you can give it any name you like.
And with that name and a semicolon it stops the heredoc statement.
The code between like html is not the problem it’s the name how can I
Create a parser rule for it if the name is not constant

<HereDoc_statement>
::= ‘<<<’ variable <code> variable ‘; ‘

Like in this rule above the variable has to be the same
For everytime the parser goes in this rule

<<< heredoc “code” heredoc;
Or
<<< new “code” new;

Does anyone know if it’s possible to write a grammar rule for such a
thing?
Greetings Bas,
> dave.do...@gmail.com- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Dave Dolan

unread,
Jul 8, 2008, 7:19:42 AM7/8/08
to gold-pars...@googlegroups.com
That wouldn't be a rule in the grammar no. You'd have to have

Identifier <<< <Foobar>... Identifier

And then check them in your reductions to make sure they make sense.  In my mind it's on par with 'significant white space' in something like Python, you can't easily write something like that into a grammar either, especially when it is relative to the starting point.

Most of the engines have some way to do some event when a reduction is detected or to fire an event (in the case of the .net ones) when a reduction happens.  At these places you can check the start and end tokens for something identical.
dave....@gmail.com
Reply all
Reply to author
Forward
0 new messages