Skip to content

release 1.0.0 on master #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 115 commits into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
76aa80e
Merge pull request #44 from glayzzle/master
ichiriac Dec 27, 2016
37a17ae
implement nodes flags & add tests on classes
ichiriac Dec 27, 2016
b9b63cb
implement traits usage
ichiriac Dec 27, 2016
0249eb4
fix doc
ichiriac Dec 27, 2016
a90dd4f
start tests over trait & interface nodes
ichiriac Dec 27, 2016
1182236
rebuild nodes tree
ichiriac Dec 27, 2016
24f84ca
fix documentation nodes implementation
ichiriac Dec 27, 2016
7e2e192
fix documentation nodes implementation
ichiriac Dec 27, 2016
3fe2360
add interface node
ichiriac Dec 27, 2016
96d38f3
implement trait nodes
ichiriac Dec 27, 2016
170c7ee
rename documentation to doc
ichiriac Dec 27, 2016
9cfdf55
fix function & rename children as body
ichiriac Dec 27, 2016
9d14c69
fix trait insteadof -> identifier[]
ichiriac Dec 27, 2016
20860e3
add a new read_name_list helper
ichiriac Dec 27, 2016
deacdb4
https://github.com/glayzzle/php-parser/issues/11 change the expect re…
ichiriac Dec 27, 2016
59d2866
ignore plateform specific code
ichiriac Dec 28, 2016
7980c44
code array becomes code block nodes
ichiriac Dec 28, 2016
5ecbf5a
implement if node
ichiriac Dec 28, 2016
78f1132
fix coverage on if statements
ichiriac Dec 28, 2016
a40736e
isolate generic function into a utils.js file
ichiriac Dec 28, 2016
b99d1c8
fix doc, use block node instead []
ichiriac Dec 28, 2016
8e9ba7f
implement while & do nodes
ichiriac Dec 28, 2016
353ada4
implement for nodes
ichiriac Dec 28, 2016
1b38288
fix list node
ichiriac Dec 28, 2016
4ea9ac0
fix & byref for vars
ichiriac Dec 28, 2016
4005e58
add a list node
ichiriac Dec 28, 2016
ebae0aa
add coverage on list statements - wip
ichiriac Dec 28, 2016
136d2bf
add foreach node & rebuild docs
ichiriac Dec 28, 2016
fc06912
remove old tests installation requirements
ichiriac Dec 28, 2016
2c8a405
avoid including other docs into readme
ichiriac Dec 28, 2016
28d255d
https://github.com/glayzzle/php-parser-tests/issues/1
ichiriac Dec 28, 2016
89bb053
https://github.com/glayzzle/php-parser-tests/issues/1
ichiriac Dec 28, 2016
73efd7f
prepare release text
ichiriac Dec 28, 2016
c292bc6
fix tests
ichiriac Dec 28, 2016
eeff19c
remove unused references
ichiriac Dec 28, 2016
b748a0d
remove old dependencies
ichiriac Dec 28, 2016
3a59f39
fix coverage
ichiriac Dec 28, 2016
b952c64
update texts
ichiriac Dec 28, 2016
67c9d01
enable open/close tags on eval mode
ichiriac Dec 28, 2016
84ef031
implement switch, case, break nodes
ichiriac Dec 28, 2016
794d765
implement switch, case, break nodes
ichiriac Dec 28, 2016
d520b9f
add goto, label, post nodes
ichiriac Dec 28, 2016
b7f1483
cache node modules in order to speed up builds
ichiriac Dec 28, 2016
2fdd9fa
add try/catch and call nodes
ichiriac Dec 28, 2016
1721238
implement namespace & use nodes (fix https://github.com/glayzzle/php-…
ichiriac Dec 29, 2016
4585ca4
fix https://github.com/glayzzle/php-parser/issues/45 & add some tests
ichiriac Dec 29, 2016
daaf93e
add bin, cast & unary nodes
ichiriac Dec 29, 2016
f674b9f
add bin, cast & unary nodes
ichiriac Dec 29, 2016
aab775b
add bool & retif nodes
ichiriac Dec 30, 2016
88871e0
add silent node
ichiriac Dec 30, 2016
5747a93
add pre node
ichiriac Dec 30, 2016
0bdb379
add new node
ichiriac Dec 30, 2016
ae9fea9
cover ast.js
ichiriac Dec 30, 2016
d75ddd7
add closure node
ichiriac Dec 30, 2016
f74c40a
improve strings coverage on lexer
ichiriac Dec 30, 2016
59760a8
test here doc on lexer
ichiriac Dec 30, 2016
0206c33
rename var.identifier to var.name + enable array tests
ichiriac Dec 30, 2016
adb7f39
fix columns implementation
ichiriac Dec 30, 2016
4039451
fix positions retrieval
ichiriac Dec 30, 2016
91010c0
eat next token before result (fix positions)
ichiriac Dec 30, 2016
4c87f29
fix positions on assign nodes
ichiriac Dec 30, 2016
78ca985
fix var name location
ichiriac Dec 30, 2016
a874732
enable new tests
ichiriac Dec 30, 2016
cdb9f42
fix & test simple_variable parsing
ichiriac Dec 30, 2016
55c96a7
add new lookup nodes & migrate vars (wip)
ichiriac Dec 30, 2016
2143b98
add the static lookup node
ichiriac Dec 30, 2016
ad2b9ab
add global node
ichiriac Dec 31, 2016
0573362
start testing numbers
ichiriac Jan 1, 2017
1901702
cover tests on initial parser
ichiriac Jan 1, 2017
a64128b
fix comment lexing & add tests (wip)
ichiriac Jan 1, 2017
6fd68be
fix scalar endeless loop (edge) + cover strings lexer
ichiriac Jan 1, 2017
f8e0455
Merge pull request #47 from glayzzle/1.0.0
ichiriac Jan 1, 2017
e6d4e37
add some tests on binary node
ichiriac Jan 1, 2017
eeb00b8
fix empty arrays
ichiriac Jan 1, 2017
53318c4
implement the throw node
ichiriac Jan 1, 2017
36e64a8
add static keyword node
ichiriac Jan 1, 2017
9ad99b6
add the variadic node
ichiriac Jan 1, 2017
658f396
handle optional level argument on break & continue statements
ichiriac Jan 1, 2017
4f94f6d
implement the declare node
ichiriac Jan 2, 2017
8972928
handle errors with a SyntaxError error
ichiriac Jan 2, 2017
9660945
fix error properties
ichiriac Jan 2, 2017
7d47ac9
remove unused vars & update docs
ichiriac Jan 2, 2017
94145ab
add the halt compiler node
ichiriac Jan 2, 2017
b8e632d
cover fallback mode
ichiriac Jan 2, 2017
a07fe16
add a parenthesis node & implement operators precedence
ichiriac Jan 2, 2017
521891c
add more tests on expr precedence
ichiriac Jan 2, 2017
b19eeb0
add tests on tokens
ichiriac Jan 2, 2017
fefbccf
https://github.com/glayzzle/php-parser/issues/46 add an encapsed node
ichiriac Jan 2, 2017
43661db
https://github.com/glayzzle/php-parser/issues/46 add a specific node …
ichiriac Jan 2, 2017
309afd7
https://github.com/glayzzle/php-parser/issues/46 register new nodes
ichiriac Jan 2, 2017
0fb9353
implement encapsed nodes
ichiriac Jan 2, 2017
5ef26e8
add yield & yield from nodes
ichiriac Jan 2, 2017
0552a20
release dist
ichiriac Jan 2, 2017
79fc7e1
new nodes
ichiriac Jan 2, 2017
28288ba
remove unused function
ichiriac Jan 2, 2017
7526ea2
improve string tests
ichiriac Jan 2, 2017
6f778bb
add scalar tests & remove unused path
ichiriac Jan 2, 2017
4dcc871
remove dead code (parsed from expr)
ichiriac Jan 2, 2017
9047eca
remove dead code (old method scan method)
ichiriac Jan 2, 2017
3118334
fix class namespace reading on new statements
ichiriac Jan 2, 2017
f504ddd
remove dead case
ichiriac Jan 2, 2017
a8cbde6
improve parser coverage
ichiriac Jan 2, 2017
2fa6bce
dead line
ichiriac Jan 2, 2017
799e911
improve statement coverage
ichiriac Jan 2, 2017
e80e9be
improve statements coverage
ichiriac Jan 2, 2017
b094350
remove unused function
ichiriac Jan 2, 2017
26c187b
revert back deferencable + add tests
ichiriac Jan 2, 2017
97fff46
let top statements in T_DECLARE bodies
ichiriac Jan 2, 2017
1e0a01d
fix lexer state on ST_LOOKING_FOR_PROPERTY
ichiriac Jan 3, 2017
05b0eb3
add some references
ichiriac Jan 3, 2017
ced1ae3
fix continue/break statement with optional level expression
ichiriac Jan 3, 2017
1df5350
update informations
ichiriac Jan 3, 2017
fcf9e7d
rebuild
ichiriac Jan 3, 2017
239daef
up
ichiriac Jan 3, 2017
d045009
Merge pull request #52 from glayzzle/develop
ichiriac Jan 3, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .gitmodules

This file was deleted.

5 changes: 3 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bin/
/test/
/docs/
/test/
/gruntfile.js
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: node_js
node_js:
- '0.12'
cache:
bundler: true
directories:
- node_modules # NPM package
notifications:
email: false
webhooks:
Expand All @@ -9,11 +13,5 @@ notifications:
on_success: change
on_failure: always
on_start: never
before_script:
- sudo apt-get install python-software-properties -y
- sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php -y
- sudo apt-get update -y
- sudo apt-get install php7.0 php7.0-xml -y
- php -v
script: npm run cover
after_success: cat /home/travis/build/glayzzle/php-parser/coverage/lcov.info | /home/travis/build/glayzzle/php-parser/node_modules/coveralls/bin/coveralls.js
120 changes: 69 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,107 @@
php-parser
==========

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).
This javascript library parses PHP code and convert it to AST.

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


# Install it
Installation
------------

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

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

```sh
$ cd bin
$ node test.js -e "echo 'Hello World';"
npm install php-parser --save
```

Will output :
Usage
-----

```js
*** START TESTING ***
// initialize the php parser factory class
var engine = require('php-parser');
// initialize a new parser instance
var parser = new engine({
// some options :
parser: {
extractDoc: true
},
ast: {
withPositions: true
}
});

// Retrieve the AST from the specified source
var AST = parser.parseEval('echo "Hello World";');
// AST.kind === 'program';
// AST.children[0].kind === 'echo';

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

-- AST :
Sample AST output
-----------------

[
'program', <-- program node
[
[ 'sys', <-- first child, typed system call
'echo', <-- operation echo
[
[ 'string', '"Hello World"' ] <-- first argument
```js
{
'kind': 'program',
'children': [
{
'kind': 'echo',
'arguments': [
{
'kind': 'string',
'isDoubleQuote': true,
'value': 'Hello World'
}
]
]
}
]
]
}
```

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

# Use it
API Overview
------------

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

// how to retrieve the AST
var AST = parser.parseEval('echo "Hello World";');
- **parseEval**(String buffer) : parse a PHP code in eval style mode (without php open tags)
- **parseCode**(String buffer, String filename) : parse a PHP code by using php open tags.
- **tokenGetAll**(String buffer) : retrieves a list of all tokens from the specified input.

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

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

# Join the dev
- [AST nodes definition](https://github.com/glayzzle/php-parser/blob/master/docs/AST.md)
- [List of options](https://github.com/glayzzle/php-parser/wiki/Options)
- [Main API](https://github.com/glayzzle/php-parser/tree/master/docs)
- [Lexer API](https://github.com/glayzzle/php-parser/blob/master/docs/lexer.md)
- [Parser API](https://github.com/glayzzle/php-parser/blob/master/docs/parser.md)

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

The command line options :
- [php-unparser](https://github.com/chris-l/php-unparser) : Produce code that uses the style format recommended by PSR-1 and PSR-2.
- [php-writer](https://github.com/glayzzle/php-writer) : Update PHP scripts from their AST
- [ts-php-inspections](https://github.com/DaGhostman/ts-php-inspections) : Provide PHP code inspections written in typescript
- [php-reflection](https://github.com/glayzzle/php-reflection) : Reflection API for PHP files
- [wp-pot](https://github.com/rasmusbe/wp-pot) : Generate pot file for WordPress plugins and themes
- [crane](https://github.com/HvyIndustries/crane) : PHP Intellisense/code-completion for VS Code

```sh
Usage: test [options] [-f] <file>

-f <file> Parse and test the specified file
-d <path> Parse each file in the specified path
-r Use recursivity with the specified path
-e Eval the specified input and shows AST
-v Enable verbose mode and show debug
-h, --help Print help and exit
```

If you run into problems with a test, run it with the cli and add the `--debug` flag.
> You can add here your own project by opening an issue request.

# Misc

This library is released under BSD-3 license clause.

If you want to contribute please visit this repository https://github.com/glayzzle/php-parser-dev.
9 changes: 9 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Releases

## 1.0.0 : (2017-01-03)

- All nodes are now converted to objects
- Bruteforce tests are in a separate project
- Improved tests with mocha
- Many syntax fixes
- Tests over a silent error mode
- Release of a complete AST documentation

## 0.1.5 : (2016-12-27)

> The 0.1.x version starts to be deprecated
Expand Down
Loading