Re: [PHP] PHP parser extension?
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... Have you tried the tokenizer? Should be able to build what you're talking about with that (unless you just want hooks or something). http://www.php.net/tokenizer Thanks, I didn't know that exists... Unfortunatelly it is still very immature (curious - i would think they would just take zend-scanner.l for this job) and doesn't parse the code - but it will suffice for a job I have in mind. Thank you again! Anze -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP parser extension?
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
RE: [PHP] PHP parser extension?
-Original Message- From: anzenews [mailto:[EMAIL PROTECTED] Sent: 23 June 2003 11:21 I hope this is the right newsgroup for posting this... PHP.dev doesn't seem to be alive anymore? It was renamed 'internals' a while ago (see http://www.php.net/mailing-lists.php). Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP parser extension?
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
Re: [PHP] PHP parser extension?
On Mon, 2003-06-23 at 03:21, 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... Have you tried the tokenizer? Should be able to build what you're talking about with that (unless you just want hooks or something). http://www.php.net/tokenizer -- Torben Wilson [EMAIL PROTECTED]+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php