Skip to content

Commit

Permalink
Merge pull request #52 from glayzzle/develop
Browse files Browse the repository at this point in the history
Prepare to release 1.0.0
  • Loading branch information
ichiriac authored Jan 3, 2017
2 parents e6d4e37 + 239daef commit d045009
Show file tree
Hide file tree
Showing 48 changed files with 3,527 additions and 1,074 deletions.
93 changes: 71 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +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
------------

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

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

# Use it
Usage
-----

```js
// initialize the php parser factory class
var engine = require('php-parser');
// initialize a new parser instance
var parser = require('php-parser').create();

// how to retrieve the AST
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';

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

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

# Output
Sample AST output
-----------------

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

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

# Contributing
API Overview
------------

If you want to contribute please visit this repository https://github.com/glayzzle/php-parser-dev.
The main API exposes a class with the following methods :

- **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.

You can also [pass options](https://github.com/glayzzle/php-parser/wiki/Options) that change the behavior of the parser/lexer.

Documentation
-------------

- [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)

Related projects
----------------

- [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

> 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.
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Releases

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

- All nodes are now converted to objects
- Bruteforce tests are in a separate project
Expand Down
Loading

0 comments on commit d045009

Please sign in to comment.