Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/glayzzle/php-parser

:herb: NodeJS PHP Parser - extract AST or tokens
https://github.com/glayzzle/php-parser

ast development javascript lexer parser php php-ast php-parser static-code-analysis tokenizer

Last synced: 27 days ago
JSON representation

:herb: NodeJS PHP Parser - extract AST or tokens

Awesome Lists containing this project

README

        

php-parser







This JavaScript library parses PHP code and converts it to an AST.

## Installation

This library is distributed with [npm](https://www.npmjs.com/package/php-parser) :

```sh
npm install php-parser --save
```

## Usage

```js
// initialize the php parser factory class
const fs = require("fs");
const path = require("path");
const engine = require("php-parser");

// initialize a new parser instance
const parser = new engine({
// some options :
parser: {
extractDoc: true,
php7: true,
},
ast: {
withPositions: true,
},
});

// Retrieve the AST from the specified source
const eval = parser.parseEval('echo "Hello World";');

// Retrieve an array of tokens (same as php function token_get_all)
const tokens = parser.tokenGetAll(' You can add here your own project by opening an issue request.

## License

This library is released under BSD-3 license clause.