Skip to content

Commit 1df5350

Browse files
committed
update informations
1 parent ced1ae3 commit 1df5350

File tree

3 files changed

+73
-24
lines changed

3 files changed

+73
-24
lines changed

README.md

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,107 @@
11
php-parser
22
==========
33

4-
Parse PHP code from NodeJS and convert it to AST. This library is a standalone module of a larger project named [Glayzzle](http://glayzzle.com).
4+
This javascript library parses PHP code and convert it to AST.
55

66
[![npm version](https://badge.fury.io/js/php-parser.svg)](https://www.npmjs.com/package/php-parser)
77
[![Build Status](https://travis-ci.org/glayzzle/php-parser.svg)](https://travis-ci.org/glayzzle/php-parser)
88
[![Coverage Status](https://img.shields.io/coveralls/glayzzle/php-parser.svg)](https://coveralls.io/r/glayzzle/php-parser)
99
[![Gitter](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/glayzzle/Lobby)
1010

1111

12-
# Install it
12+
Installation
13+
------------
14+
15+
This library is distributed with [npm](https://www.npmjs.com/package/php-parser) :
1316

1417
```sh
15-
$ npm install php-parser --save
18+
npm install php-parser --save
1619
```
1720

18-
# Use it
21+
Usage
22+
-----
1923

2024
```js
25+
// initialize the php parser factory class
26+
var engine = require('php-parser');
2127
// initialize a new parser instance
22-
var parser = require('php-parser').create();
23-
24-
// how to retrieve the AST
28+
var parser = new engine({
29+
// some options :
30+
parser: {
31+
extractDoc: true
32+
},
33+
ast: {
34+
withPositions: true
35+
}
36+
});
37+
38+
// Retrieve the AST from the specified source
2539
var AST = parser.parseEval('echo "Hello World";');
40+
// AST.kind === 'program';
41+
// AST.children[0].kind === 'echo';
2642

27-
// how to list tokens
43+
// Retrieve an array of tokens (same as php function token_get_all)
2844
var tokens = parser.tokenGetAll('<?php echo "Hello World";');
2945
```
3046

31-
For more details please [visit he wiki](https://github.com/glayzzle/php-parser/docs).
32-
33-
# Output
47+
Sample AST output
48+
-----------------
3449

3550
```js
36-
[
37-
'program', <-- program node
38-
[
39-
[ 'sys', <-- first child, typed system call
40-
'echo', <-- operation echo
41-
[
42-
[ 'string', '"Hello World"' ] <-- first argument
51+
{
52+
'kind': 'program',
53+
'children': [
54+
{
55+
'kind': 'echo',
56+
'arguments': [
57+
{
58+
'kind': 'string',
59+
'isDoubleQuote': true,
60+
'value': 'Hello World'
61+
}
4362
]
44-
]
63+
}
4564
]
46-
]
65+
}
4766
```
4867

4968
Try it online (demo) :
5069
http://glayzzle.com/php-parser/#demo
5170

52-
# Contributing
71+
API Overview
72+
------------
5373

54-
If you want to contribute please visit this repository https://github.com/glayzzle/php-parser-dev.
74+
The main API exposes a class with the following methods :
75+
76+
- **parseEval**(String buffer) : parse a PHP code in eval style mode (without php open tags)
77+
- **parseCode**(String buffer, String filename) : parse a PHP code by using php open tags.
78+
- **tokenGetAll**(String buffer) : retrieves a list of all tokens from the specified input.
79+
80+
You can also [pass options](https://github.com/glayzzle/php-parser/wiki/Options) that change the behavior of the parser/lexer.
81+
82+
Documentation
83+
-------------
84+
85+
- [AST nodes definition](https://github.com/glayzzle/php-parser/blob/master/docs/AST.md)
86+
- [List of options](https://github.com/glayzzle/php-parser/wiki/Options)
87+
- [Main API](https://github.com/glayzzle/php-parser/tree/master/docs)
88+
- [Lexer API](https://github.com/glayzzle/php-parser/blob/master/docs/lexer.md)
89+
- [Parser API](https://github.com/glayzzle/php-parser/blob/master/docs/parser.md)
90+
91+
Related projects
92+
----------------
93+
94+
- [php-unparser](https://github.com/chris-l/php-unparser) : Produce code that uses the style format recommended by PSR-1 and PSR-2.
95+
- [php-writer](https://github.com/glayzzle/php-writer) : Update PHP scripts from their AST
96+
- [ts-php-inspections](https://github.com/DaGhostman/ts-php-inspections) : Provide PHP code inspections written in typescript
97+
- [php-reflection](https://github.com/glayzzle/php-reflection) : Reflection API for PHP files
98+
- [wp-pot](https://github.com/rasmusbe/wp-pot) : Generate pot file for WordPress plugins and themes
99+
- [crane](https://github.com/HvyIndustries/crane) : PHP Intellisense/code-completion for VS Code
100+
101+
> You can add here your own project by opening an issue request.
55102
56103
# Misc
57104

58105
This library is released under BSD-3 license clause.
106+
107+
If you want to contribute please visit this repository https://github.com/glayzzle/php-parser-dev.

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Releases
22

3-
## 1.0.0 : (2016-12-29)
3+
## 1.0.0 : (2017-01-03)
44

55
- All nodes are now converted to objects
66
- Bruteforce tests are in a separate project

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "php-parser",
33
"version": "1.0.0",
4-
"description": "Parse PHP code with NodeJS and convert it to AST",
4+
"description": "Parse PHP 5/7 code and returns its AST",
55
"main": "src/index.js",
66
"scripts": {
77
"test": "node node_modules/mocha/bin/mocha test --stack-size=5000",

0 commit comments

Comments
 (0)