package
Parse PHP code from JS and returns its AST
npm install php-parserGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
825.7 kB
Includes dependencies.
This JavaScript library parses PHP code and converts it to an AST.
This library is distributed with npm :
npm install php-parser --save// 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(
{
'kind': 'program',
'children': [
{
'kind': 'echo',
'arguments': [
{
'kind': 'string',
'isDoubleQuote': true,
'value': 'Hello World'
}
]
}
]
}The main API exposes a class with the following methods :
You can also pass options that change the behavior of the parser/lexer.
You can add here your own project by opening an issue request.
This library is released under BSD-3 license clause.
czosel
christian@zosel.ch