Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/glayzzle/php-parser
- Owner: glayzzle
- License: bsd-3-clause
- Created: 2014-12-07T10:11:57.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-03-08T06:18:00.000Z (8 months ago)
- Last Synced: 2024-04-14T04:43:46.241Z (7 months ago)
- Topics: ast, development, javascript, lexer, parser, php, php-ast, php-parser, static-code-analysis, tokenizer
- Language: JavaScript
- Homepage: https://php-parser.glayzzle.com/
- Size: 29.5 MB
- Stars: 513
- Watchers: 19
- Forks: 67
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- favorite-link - 这个 javascript 库解析 PHP 代码并将其转换为 AST。
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.