Skip to content

Commit be2decb

Browse files
authored
Merge pull request glayzzle#53 from glayzzle/1.0.0
release 1.0.0 on master
2 parents 1a27f8d + d045009 commit be2decb

File tree

179 files changed

+9667
-8479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+9667
-8479
lines changed

.gitmodules

-36
This file was deleted.

.npmignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
/bin/
2-
/test/
1+
/docs/
2+
/test/
3+
/gruntfile.js

.travis.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
language: node_js
22
node_js:
33
- '0.12'
4+
cache:
5+
bundler: true
6+
directories:
7+
- node_modules # NPM package
48
notifications:
59
email: false
610
webhooks:
@@ -9,11 +13,5 @@ notifications:
913
on_success: change
1014
on_failure: always
1115
on_start: never
12-
before_script:
13-
- sudo apt-get install python-software-properties -y
14-
- sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php -y
15-
- sudo apt-get update -y
16-
- sudo apt-get install php7.0 php7.0-xml -y
17-
- php -v
1816
script: npm run cover
1917
after_success: cat /home/travis/build/glayzzle/php-parser/coverage/lcov.info | /home/travis/build/glayzzle/php-parser/node_modules/coveralls/bin/coveralls.js

README.md

+69-51
Original file line numberDiff line numberDiff line change
@@ -1,89 +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+
------------
1314

14-
```sh
15-
$ npm install php-parser --save
16-
```
17-
18-
# Try it
15+
This library is distributed with [npm](https://www.npmjs.com/package/php-parser) :
1916

2017
```sh
21-
$ cd bin
22-
$ node test.js -e "echo 'Hello World';"
18+
npm install php-parser --save
2319
```
2420

25-
Will output :
21+
Usage
22+
-----
23+
2624
```js
27-
*** START TESTING ***
25+
// initialize the php parser factory class
26+
var engine = require('php-parser');
27+
// initialize a new parser instance
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
39+
var AST = parser.parseEval('echo "Hello World";');
40+
// AST.kind === 'program';
41+
// AST.children[0].kind === 'echo';
2842

29-
-- TOKENS :
30-
T_ECHO T_CONSTANT_ENCAPSED_STRING ;
43+
// Retrieve an array of tokens (same as php function token_get_all)
44+
var tokens = parser.tokenGetAll('<?php echo "Hello World";');
45+
```
3146

32-
-- AST :
47+
Sample AST output
48+
-----------------
3349

34-
[
35-
'program', <-- program node
36-
[
37-
[ 'sys', <-- first child, typed system call
38-
'echo', <-- operation echo
39-
[
40-
[ 'string', '"Hello World"' ] <-- first argument
50+
```js
51+
{
52+
'kind': 'program',
53+
'children': [
54+
{
55+
'kind': 'echo',
56+
'arguments': [
57+
{
58+
'kind': 'string',
59+
'isDoubleQuote': true,
60+
'value': 'Hello World'
61+
}
4162
]
42-
]
63+
}
4364
]
44-
]
65+
}
4566
```
4667

4768
Try it online (demo) :
4869
http://glayzzle.com/php-parser/#demo
4970

50-
# Use it
71+
API Overview
72+
------------
5173

52-
```js
53-
// initialize a new parser instance
54-
var parser = require('php-parser').create();
74+
The main API exposes a class with the following methods :
5575

56-
// how to retrieve the AST
57-
var AST = parser.parseEval('echo "Hello World";');
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.
5879

59-
// how to list tokens
60-
var tokens = parser.tokenGetAll('<?php echo "Hello World";');
61-
```
80+
You can also [pass options](https://github.com/glayzzle/php-parser/wiki/Options) that change the behavior of the parser/lexer.
6281

63-
For more details please [visit he wiki](https://github.com/glayzzle/php-parser/wiki).
82+
Documentation
83+
-------------
6484

65-
# Join the dev
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)
6690

67-
If you want to change/fix the lexer you will find code to `./src/lexer/`.
68-
You can also implement the parser, the code is into `./src/parser/`.
69-
To check your changes add tests into `./test/parser/`, and run `npm run test`.
70-
Try to keep or improve the coverage levels.
91+
Related projects
92+
----------------
7193

72-
The command line options :
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
73100

74-
```sh
75-
Usage: test [options] [-f] <file>
76-
77-
-f <file> Parse and test the specified file
78-
-d <path> Parse each file in the specified path
79-
-r Use recursivity with the specified path
80-
-e Eval the specified input and shows AST
81-
-v Enable verbose mode and show debug
82-
-h, --help Print help and exit
83-
```
84-
85-
If you run into problems with a test, run it with the cli and add the `--debug` flag.
101+
> You can add here your own project by opening an issue request.
86102
87103
# Misc
88104

89105
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

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Releases
22

3+
## 1.0.0 : (2017-01-03)
4+
5+
- All nodes are now converted to objects
6+
- Bruteforce tests are in a separate project
7+
- Improved tests with mocha
8+
- Many syntax fixes
9+
- Tests over a silent error mode
10+
- Release of a complete AST documentation
11+
312
## 0.1.5 : (2016-12-27)
413

514
> The 0.1.x version starts to be deprecated

0 commit comments

Comments
 (0)