5 ms·
> What is the purpose of this? Just static analysis? I'm not sure about the "Just" here. The opportunities for writing code transformation tools are abundant.
by sshine 9y ago
> What is the purpose of this? Just static analysis?
I'm not sure about the "Just" here.
The opportunities for writing code transformation tools are abundant. E.g. a PHP IDE that isn't written in PHP, a linting tool, a preprocessor for an embedded DSL. It isn't obvious to me that the tooling for a language like PHP need to be written in PHP.
> Why Go?
Go isn't a bad choice for writing parts of a compiler. The parser itself was, however, written with the parser generator goyacc rather than native Go code:
https://github.com/z7zmey/php-parser/blob/master/php7/php7.y https://github.com/z7zmey/php-parser/blob/master/php7/php7.y
Taking a goyacc file like this and porting it to another YACC is a lower effort than starting from scratch. In such a way, this project delivers not just "a PHP parser with xx% coverage in Go", but a shortcut to writing PHP parsers in any language with a decent YACC.
One way this project is structured that I don't particularly like is that each node in the AST corresponds to a file. For a programming language with algebraic types (ML, Haskell), having the AST definition in a single file is quite typical.
https://github.com/z7zmey/php-parser/tree/master/node/expr https://github.com/z7zmey/php-parser/tree/master/node/expr
- johannes1234321 9y ago> Taking a goyacc file like this and porting it to another YACC is a lower effort than starting from scratch. In such a way, this project delivers not just "a PHP parser with xx% coverage in Go", but a shortcut to writing PHP parsers in any language with a decent YACC. There's already a yacc file for PHP's parser, part of the PHP runtime: https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y https://github.com/php/php-src/blob/master/Zend/zend_languag...