Last active
January 3, 2017 12:18
-
-
Save ichiriac/0b6718e90bb098dfba687df9ca7a0bb8 to your computer and use it in GitHub Desktop.
A simple usage of php-parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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