Skip to content

Instantly share code, notes, and snippets.

@ichiriac
Last active January 3, 2017 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichiriac/0b6718e90bb098dfba687df9ca7a0bb8 to your computer and use it in GitHub Desktop.
Save ichiriac/0b6718e90bb098dfba687df9ca7a0bb8 to your computer and use it in GitHub Desktop.
A simple usage of php-parser
var parser = require('php-parser');
// initialize a new parser instance
var instance = new parser({
parser: {
extractDoc: true,
suppressErrors: true
},
ast: {
withPositions: true
},
lexer: {
short_tags: true,
asp_tags: true
}
});
// how to retrieve the AST
var evalAST = instance.parseEval('some php code');
// or
var codeAST = instance.parseCode('<?php some php code', 'foo.php');
// how to list tokens
var tokens = instance.tokenGetAll('<?php some php code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment