Show HN: A PHP parser written in PHP
github.com
github.com
[1] http://alexrosen.com/blog/2011/05/sponge-learning/
edit: grammar.
But more formally, a self-hosting compiler says stuff about the language per se, see also http://en.wikipedia.org/wiki/Bootstrapping_(compilers).
That it's Turing-complete and can write to a file? I think all it really says is that somebody was hard-headed enough to do it.
The fact that it is written in PHP is nice because it allows you to use it in existing PHP projects in an environment you are already familiar with. I think the fact that it is written in PHP is less important than the fact that it can be used in PHP (e.g. it would be equally useful as a PHP extension written in C).
And there is nothing bad with this. It is just that many authors don't want to articulate on this and are trying to come up with some artificial rationales.
If you're making a template language for use in a SaaS system, you'd want to perhaps allow echo, but not file_put_contents.
1: http://www.smarty.net/ 2: https://en.wikipedia.org/wiki/Inner-platform_effect
But, you can make just as readable code without smarty and load times are much faster (although smarty does have a caching system).
And caching..on disk, who cares? In general, dO we not have better, faster and more versitile options that would in any way justify a choice for smarty?
I have one reason for not using Smarty in my more recent work but it has nothing to do with my feelings about Smarty itself. Rather just that a lot of web apps lately have all of the view logic in the client. So the server rendering of the view is often just outputting mostly static HTML for the Javascript to use as it's starting point. So it's not that I dislike Smarty, it's just that there's barely any logic at all happening at that level so there's no need for it.
Disclaimer: I've never had to use this, so don't know what the limitations and pitfalls are for this, and there may be security concerns that I'm unaware of.
[1] http://www.php.net/manual/en/ini.core.php#ini.disable-functi...
I believe it's much faster too.
I saw this in Horde, the other day; mixed in with the usual PHP tags they had added their own XML tags for doing "if/else" type things in the template. What is the purpose of that?
...which I think is retarded and anal, since the important part is separation of business logic and presentation. There is bound to be some level of display logic, which is why most template languages have loops and conditionals. But if you are going that far, why not just use PHP? It is arguably a very good template language.
The parser is more for analyzers that are not interested in the precise formatting of the code, but want to look at the code from a higher level perspective.
For example, if you want to do control flow analysis and type inference working directly on the tokens would be really hard. An Abstract Syntax Tree makes this kind of work much easier, as you don't have to think about the tiny details of the language.
Certainly this project doesn't get us there immediately, but might give some neat ideas for future PHP versions to incorporate.
http://us3.php.net/manual/en/function.token-get-all.php http://us3.php.net/manual/en/function.token-name.php
Very cool nonetheless.
Well done with the project--I have a use case for it regarding enforcing PHP style guide @ $work.