PHP-To-AST
![Build Status](https://github.com/uniter/phptoast/workflows/CI/badge.svg)
PHP-to-AST parser.
Defining syntax extensions
Sometimes it can be handy to extend PHP's syntax with custom constructs.
You can modify and extend PHPToAST's built-in grammar with the options
argument passed to .create(...)
.
For example:
var phpParser = require('phptoast').create(null, {
rules: {
'N_CUSTOM_TRAP_IT': {
components: [/trap_it/, /@/, {name: 'arg', rule: 'N_EXPRESSION'}, /;/]
},
'N_NAMESPACE_SCOPED_STATEMENT': {
components: {oneOf: ['N_CUSTOM_TRAP_IT', 'N_NAMESPACE_SCOPED_STATEMENT']}
}
}
});
console.log(JSON.stringify(phpParser.parse('<?php firstFunc(); trap_it @ 21; secondFunc();'), null, 4));
Keeping up to date