new engine(options)
Initialise a new parser instance with the specified options
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Object |
List of options |
Properties:
| Name | Type | Description |
|---|---|---|
lexer |
Lexer | |
parser |
Parser | |
ast |
AST | |
tokens |
Object |
Example
var parser = require('php-parser');
var instance = new parser({
parser: {
extractDoc: true,
suppressErrors: true,
php7: true
},
ast: {
withPositions: true
},
lexer: {
short_tags: true,
asp_tags: true
}
});
var evalAST = instance.parseEval('some php code');
var codeAST = instance.parseCode('<?php some php code', 'foo.php');
var tokens = instance.tokenGetAll('<?php some php code');
Methods
parseCode(buffer, filename) → {Program}
Function that parse a php code with open/close tags
Sample code :
<?php $x = 1;
Usage :
var parser = require('php-parser');
var phpParser = new parser({
// some options
});
var ast = phpParser.parseCode('...php code...', 'foo.php');
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
String |
The code to be parsed |
filename |
String |
Filename |
parseEval(buffer) → {Program}
Parse an evaluating mode string (no need to open php tags)
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
String |
tokenGetAll(buffer) → {Array.<String>}
Extract tokens from the specified buffer.
Note that the output tokens are STRICLY similar to PHP function
token_get_all
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
String |