Skip to content

Turn input into string in case is a buffer #90

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 4 commits into from
Sep 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ Usage

```js
// initialize the php parser factory class
var fs = require('fs');
var path = require('path');
var engine = require('php-parser');

// initialize a new parser instance
var parser = new engine({
// some options :
Expand All @@ -35,12 +38,19 @@ var parser = new engine({
});

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

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

// Load a static file (Note: this file should exist on your computer)
var phpFile = fs.readFileSync( './example.php' );

// Log out results
console.log( 'Eval parse:', eval );
console.log( 'Tokens parse:', tokens );
console.log( 'File parse:', parser.parseCode(phpFile) );

```

Sample AST output
Expand Down Expand Up @@ -72,9 +82,9 @@ API Overview

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

Expand Down
Loading