Skip to content

Commit

Permalink
Merge pull request #53 from glayzzle/1.0.0
Browse files Browse the repository at this point in the history
release 1.0.0 on master
  • Loading branch information
ichiriac authored Jan 3, 2017
2 parents 1a27f8d + d045009 commit be2decb
Show file tree
Hide file tree
Showing 179 changed files with 9,667 additions and 8,479 deletions.
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

0 comments on commit be2decb

Please sign in to comment.