I don't know that this kind of funcitonality exists, but that would be
a sweet deal if it did.
Cheers,
Rob.
anzenews wrote:
Hi!
I hope this is the right newsgroup for posting this... PHP.dev doesn't seem
to be alive anymore?
Is there some extension or anything that would allow me to hook my code to
PHP parser? Even lex and yacc for PHP would be great...
What I want to do is this: lets say tou want to extract all comments from
PHP code. Sure, you can search for '/*' and '*/', and take everything in
between as a comment, but it is not really an idiot-proof way of doing it.
The Right Way (tm) would be to have a parser to do it. There are no tools
to produce a parser in PHP available (at least to my knowledge) and we
don't want to build it from the scratch (it is possible, but not the
easiest way) - but we do have tools that could build such parser in C (lex
yacc). And since C is the language used for writing extensions to PHP, we
can do it - we just take zend-scanner.l and zend-parser.y and replace all
the code that interprets PHP with the code that prints out comments - piece
of cake. The only problem is - I really wouldn't want to dl() it every time
I need it, not to mention the fact that it is not possible with ISPs that
have secure mode enabled, besides - PHP parser changes from time to time.
To think I should have to support such code for every possible application
gives me creeps. The solution is simple: such extension should be in the
main PHP distribution, but instead of doing predetermined things (like
printing out comments) it should allow developers to hook their own
function wherever they wish - as the code was being parsed, these functions
would get called.
Now for the questions:
- has anyone done someting like this before?
- license - is it OK to take zend_scanner.l and zend_parser.y - I guess the
extension should be then published under Zend license, not GPL?
- is anyone interested in such an extension anyway?
There are many possible applications that could use such extension:
documentation generator (one that works whatever the code), obfuscator,
preprocessor,... It is advanced usage only as the developer should know
about parsers, but still...
If there is enough interest, I could throw together an API of some sort,
maybe even whole extension... Please comment, send opinions, answers,...
Please do not send mail privately as I have this address just for posting
to newsgroups - I will not receive it.
By!
Anze
(By the way, about idiot-proof programs: Programming is a race between
programmers and universe; programmers, trying to build better idiot-proof
programs, and universe, trying to build better idiots. So far, universe is
winning.)
-
Please do not send mail privately - I do NOT read mail sent
to this address, it is used only for newsgroups (spam
protection).
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
.-.
| Worlds of Carnage - http://www.wocmud.org |
:-:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the |
| stuff of nightmares grasp for your soul.|
`-'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php