[antlr-interest] Improvements to the Antlr PHP Target

Benjamin Eberlei kontakt at beberlei.de
Mon Sep 6 12:12:54 PDT 2010


Hello,

We are currently building an open-source PHP ORM
(http://www.doctrine-project.org) that utilizes a hand-written Top-Down,
Recursive-Descent Parser for our Query Language. That is why we are
looking for ways how to automate the parser generation for a future
major release to increase maintainability. This his going to be a
potential long-run refactoring for our project, so we are looking into
possible solutions as early as possible.

We know Antlr exists and have found the ongoing effort to write an Antlr
Target for PHP at http://code.google.com/p/antlrphpruntime/. However it
seems development of that target has come to halt. Additionally we had
doubts with regard to some design decisions in the Runtime engine.

Over the weekend I have forked that project at
http://github.com/beberlei/antlr-php-runtime and changed the
following stuff:

* Migrated Runtime to PHP 5.3 Namespaces (Antlr\Runtime\*)
* Fixed formatting of all files to comply to PEAR/Zend Coding Standards
(Php.stg is not yet generation compliant code)
* Fixed functional testsuite to pass up to test 41 of the Python
testsuite (with the exception of Test 22)
* Refactored testsuite to have distinct sub-directories for grammer and
generated code to enhance readibility/maintainability.
* Removed class "Set" and implemented follow sets with simple PHP arrays
for performance reasons.
* Removed "public static" token and "constants" and used PHP class
constants for performance reasons (compile vs runtime generation)
* Rewrote DFA code (although this still does not support unicode and
probably has other bugs)
* Lots of other refactorings to make use of PHP internal features.

How should the development of this target continue given that the
original code is in the Google SVN? For the namespace and test-cleanup
refactoring I moved almost all files to new directories, so this could
be a bit cumbersome to merge back (sorry for that! :()

Additionally for further development it would be helpful if anyone could
help me with these questions:

1. Is it really required to have a Runtime of "StringTemplate" library
in PHP? What is it used for at runtime? When is the ST.stg template used
at all?
2. Can i escape strings from the template generator? In <description>
there are sometimes literals of the kind "?>" which end the PHP mode
even if they are inside comments and make the code fail. I would like to
strip "?>" from each <description> I render.
3. How stable are the runtimes? I see very little commits to them, so
probably very stable. But how will that change with Antlr v4 in
development?
4. After the basic Parser/Lexer support, what would be the next step in
target development? AST support with the Tree Runtime namespace?

greetings,
Benjamin



More information about the antlr-interest mailing list