Skip to content

Commit b5008ac

Browse files
authored
Merge pull request glayzzle#90 from b4dnewz/master
Turn input into string in case is a buffer
2 parents 67a902a + 7c016b9 commit b5008ac

File tree

5 files changed

+6539
-9
lines changed

5 files changed

+6539
-9
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ Usage
2222

2323
```js
2424
// initialize the php parser factory class
25+
var fs = require('fs');
26+
var path = require('path');
2527
var engine = require('php-parser');
28+
2629
// initialize a new parser instance
2730
var parser = new engine({
2831
// some options :
@@ -35,12 +38,19 @@ var parser = new engine({
3538
});
3639

3740
// Retrieve the AST from the specified source
38-
var AST = parser.parseEval('echo "Hello World";');
39-
// AST.kind === 'program';
40-
// AST.children[0].kind === 'echo';
41+
var eval = parser.parseEval('echo "Hello World";');
4142

4243
// Retrieve an array of tokens (same as php function token_get_all)
4344
var tokens = parser.tokenGetAll('<?php echo "Hello World";');
45+
46+
// Load a static file (Note: this file should exist on your computer)
47+
var phpFile = fs.readFileSync( './example.php' );
48+
49+
// Log out results
50+
console.log( 'Eval parse:', eval );
51+
console.log( 'Tokens parse:', tokens );
52+
console.log( 'File parse:', parser.parseCode(phpFile) );
53+
4454
```
4555

4656
Sample AST output
@@ -72,9 +82,9 @@ API Overview
7282

7383
The main API exposes a class with the following methods :
7484

75-
- **parseEval**(String buffer) : parse a PHP code in eval style mode (without php open tags)
76-
- **parseCode**(String buffer, String filename) : parse a PHP code by using php open tags.
77-
- **tokenGetAll**(String buffer) : retrieves a list of all tokens from the specified input.
85+
- **parseEval**(String|Buffer) : parse a PHP code in eval style mode (without php open tags)
86+
- **parseCode**(String|Buffer, String filename) : parse a PHP code by using php open tags.
87+
- **tokenGetAll**(String|Buffer) : retrieves a list of all tokens from the specified input.
7888

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

0 commit comments

Comments
 (0)