@expreva/php-parser
v1.0.0
Published
Standalone library to parse PHP in Node.js using a PHP runtime compiled to WebAssembly
Downloads
1
Readme
PHP Parser
This is a standalone library to parse PHP in Node.js. It bundles a PHP runtime compiled to WebAssembly, so it doesn't depend on PHP being installed on the local system.
Install
npm install @expreva/php-parser
Usage
import { createPhp } from '@expreva/php-parser'
await php = await createPhp()
const code = `<?php echo 'hi';`
const {
parsed, // Node[]
error // Error
} = await php.parse(code)
console.log(parsed)
Known limitations
After using the PHP runtime instance, it is necessary to exit the process when done.
// Exit to stop PHP process
process.exit()
Abstract Syntax Tree
See https://github.com/nikic/PHP-Parser/blob/master/doc/component/JSON_representation.markdown