Skip to content

Latest commit

 

History

History
97 lines (64 loc) · 2.63 KB

Engine.md

File metadata and controls

97 lines (64 loc) · 2.63 KB

Initialise a new parser instance with the specified options

Usage :

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');

Type: Engine

Parameters

  • options Object List of options

Properties

  • lexer Lexer
  • parser Parser
  • ast AST
  • tokens Object

parseEval

Parse an evaluating mode string (no need to open php tags)

Parameters

Returns Program

parseCode

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

  • buffer String The code to be parsed
  • filename String Filename

Returns Program

tokenGetAll

Extract tokens from the specified buffer.

Note that the output tokens are STRICLY similar to PHP function token_get_all

Parameters

Returns Array<String> Each item can be a string or an array with following informations [token_name, text, line_number]

getStringBuffer

Check if the inpyt is a buffer or a string

Parameters

  • buffer (Buffer | String) Input value that can be either a buffer or a string

Returns String Returns the string from input