1.0.0 • Published 6 months ago

@expreva/php-parser v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

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

Included libraries

1.0.0

6 months ago