-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from glayzzle/develop
Prepare to release 1.0.0
- Loading branch information
Showing
48 changed files
with
3,527 additions
and
1,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
[](https://www.npmjs.com/package/php-parser) | ||
[](https://travis-ci.org/glayzzle/php-parser) | ||
[](https://coveralls.io/r/glayzzle/php-parser) | ||
[](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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.