mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 20:14:46 +01:00
24 lines
722 B
Plaintext
24 lines
722 B
Plaintext
This is a PHP parser written in PHP.
|
|
|
|
This project is work in progress, but it basically works and was tested on a large code base.
|
|
|
|
Usage:
|
|
|
|
$parser = new Parser();
|
|
$stmts = $parser->yyparse(
|
|
new Lexer('<?php // some code'),
|
|
function($msg) {
|
|
// this is the error callback, which is fired in case of
|
|
// a parse error. It is passed the error message.
|
|
echo $msg, "\n";
|
|
}
|
|
);
|
|
|
|
// the return value of Parser->yyparse will either be false (which
|
|
// signifies that an error occured) or an array of statements (Nodes)
|
|
if (false !== $stmts) {
|
|
// dump the AST
|
|
foreach ($stmts as $stmt) {
|
|
echo $stmt, "\n";
|
|
}
|
|
} |