File tree 4 files changed +6525
-7
lines changed
4 files changed +6525
-7
lines changed Original file line number Diff line number Diff line change 22
22
23
23
``` js
24
24
// initialize the php parser factory class
25
- var engine = require (' php-parser' );
25
+ var fs = require (' fs' );
26
+ var path = require (' path' );
27
+ var engine = require (' ../src/index.js' );
28
+
26
29
// initialize a new parser instance
27
30
var parser = new engine ({
28
31
// some options :
@@ -35,12 +38,19 @@ var parser = new engine({
35
38
});
36
39
37
40
// Retrieve the AST from the specified source
38
- var AST = parser .parseEval (' echo "Hello World";' );
39
- // AST.kind === 'program';
40
- // AST.children[0].kind === 'echo';
41
+ var eval = parser .parseEval (' echo "Hello World";' );
41
42
42
43
// Retrieve an array of tokens (same as php function token_get_all)
43
44
var tokens = parser .tokenGetAll (' <?php echo "Hello World";' );
45
+
46
+ // Load a static file (Note: this file should exist on your computer)
47
+ var phpFile = fs .readFileSync ( ' ./example.php' );
48
+
49
+ // Log out results
50
+ console .log ( ' Eval parse:' , eval );
51
+ console .log ( ' Tokens parse:' , tokens );
52
+ console .log ( ' File parse:' , parser .parseCode (phpFile) );
53
+
44
54
```
45
55
46
56
Sample AST output
You can’t perform that action at this time.
0 commit comments