1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# backyard-parser
Parse PHP code to AST node.
## features
- Parse string to AST _(parse() & parse_eval())_
## usage
fn main() {
let code = r#"<?php
function hello_world($foo) {
var_dump($foo);
}"#;
let parsed = backyard_parse::parse(code);
println!("{:?}", parsed);
}
Resulting this json:
Ok([
Node {
leadings: [],
trailings: [],
node_type: Function,
node: Function(FunctionNode {
is_ref: false,
name: Node {
leadings: [],
trailings: [],
node_type: Identifier,
node: Identifier(IdentifierNode { name: "hello_world" })
},
parameters: [
Node {
leadings: [],
trailings: [],
node_type: Parameter,
node: Parameter(ParameterNode {
variable_type: None,
is_ref: false,
is_ellipsis: false,
name: Node {
leadings: [],
trailings: [],
node_type: Identifier,
node: Identifier(IdentifierNode { name: "foo" })
},
value: None
})
}
],
return_type: None,
body: Some(Node {
leadings: [],
trailings: [],
node_type: Block,
node: Block(BlockNode {
statements: [
Node {
leadings: [],
trailings: [],
node_type: Call,
node: Call(CallNode {
name: Node {
leadings: [],
trailings: [],
node_type: Identifier,
node: Identifier(IdentifierNode { name: "var_dump" })
},
arguments: [
Node {
leadings: [],
trailings: [],
node_type: CallArgument,
node: CallArgument(CallArgumentNode {
name: None,
value: Node {
leadings: [],
trailings: [],
node_type: Variable,
node: Variable(VariableNode {
name: Node {
leadings: [],
trailings: [],
node_type: Identifier,
node: Identifier(IdentifierNode { name: "foo" })
}
})
}
})
}
]
})
}
]
})
})
})
}
])
## heavily inspired by
- [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser)
- [glayzzle/php-parser](https://github.com/glayzzle/php-parser)
## license
[MIT](https://github.com/Alzera/backyard/blob/main/LICENSE)