Compiler and PHP questions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Compiler and PHP questions

Joe Armstrong (AL/EAB)

1) Does anybody have or is anybody working on a parser for php written in erlang - please contact me
   if this is the case.

2) Is there an easy way to get line numbers right in transformed code?

   Suppose I have an input file foo.ehe with some embedded code:

        ...
        <h1>title</h1>
        <p>hello <? getDb "name") ?> how are you

   Into foo.erl

        foo(A) ->
            output(<<"<h1>title</h1>\n<p>hellon "),
            getDb "name"),
            output(<<" how are you">>).

    And run this through the compiler then the line number with the error
refers to foo.erl and NOT foo.ehe.

    I thought there was an annotation you could add to the source. Like this:

        -file("foo.ehe", 23)
        foo(A) ->
           ...

     To tell the compiler that foo(A) came from foo.ehe line 23.

     This seems to be broken (there *is* code in epp.erl to do this and I *can* change the
file name but *not* the line number). Is this a bug or a feature or have I misunderstood
something?

     The alternative seems to be to run a parse transform on an empty file and
transform the empty file into a parse tree with the correct line numbers in it.

/Joe


           

   


Reply | Threaded
Open this post in threaded view
|

Compiler and PHP questions

Marc van Woerkom-2
>1) Does anybody have or is anybody working on a parser
>for php written in erlang - please contact me
>    if this is the case.

I would love to know about this too, as I use PHP for my
present day job. :)

BTW Perl 6 seems to get implemented in Haskell first:

   http://www.perl.com/pub/a/2005/03/03/pugs_interview.html


> <h1>title</h1>
> <p>hello <? getDb "name") ?> how are you

Putting code fragments into HTML is not a good style for
developing (larger) web applications.

This has to do with the typical team structure / division
of labour for web teams:
- the web developers do the pure php/perl/.. script code
- the screen designers rule the template files
- the backend folks deliver methods to feed/query the
backend databases

For php we use the smarty template engine.

A template is instantiated and fed with variable data by
the web application.
The template file contains mainly html/css/javascript and
has just extra support for conditional code activiation,
data access (just to the provided variable data) and
simple repetition control, all in a HTML like syntax.

A web developer delivers just a plain template file as
result of his work, a template file that just renders the
web page in minimal stylish fashion, with all access to
the internal vars provided.

This is then fed to the screen designers who use their
javascript and DHTML magic to pimp it up.

Regards,
Marc


Reply | Threaded
Open this post in threaded view
|

Compiler and PHP questions

Hans Bolinder-3
In reply to this post by Joe Armstrong (AL/EAB)
"Joe Armstrong (AL/EAB)" <joe.armstrong>

> 2) Is there an easy way to get line numbers right in transformed code?
>
>     I thought there was an annotation you could add to the source.
>     Like this:
>
> -file("foo.ehe", 23)
> foo(A) ->
>   ...
>
>      To tell the compiler that foo(A) came from foo.ehe line 23.
>
>      This seems to be broken (there *is* code in epp.erl to do this and
>      I *can* change the file name but *not* the line number). Is this
>      a bug or a feature or have I misunderstood something?

The -file attribute has so far been used for implementing -include and
-include_lib only.

The changes necessary to make it work on "user level" have been made
in R11B to be. They are neither simple nor beautiful.

One of the first users of this new feature will be yecc.

Best regards
Hans Bolinder, Erlang/OTP