@@ -64,6 +64,53 @@ It does not change AST but collects resolved names into `map[node.Node]string`
64
64
- For ` Class ` , ` Interface ` , ` Trait ` , ` Function ` , ` ConstList ` nodes collects name with current namespace.
65
65
- For ` Name ` , ` Relative ` , ` FullyQualified ` nodes resolves ` use ` aliases and collects a fully qualified name.
66
66
67
+ ## Pretty printer
68
+
69
+ ``` Golang
70
+ nodes := &stmt.StmtList {
71
+ Stmts : []node.Node {
72
+ &stmt.Namespace {
73
+ NamespaceName: &name.Name {Parts: []node.Node {&name.NamePart {Value: " Foo" }}},
74
+ },
75
+ &stmt.Class {
76
+ Modifiers: []node.Node {&node.Identifier {Value: " abstract" }},
77
+ ClassName: &name.Name {Parts: []node.Node {&name.NamePart {Value: " Bar" }}},
78
+ Extends: &name.Name {Parts: []node.Node {&name.NamePart {Value: " Baz" }}},
79
+ Stmts: []node.Node {
80
+ &stmt.ClassMethod {
81
+ Modifiers: []node.Node {&node.Identifier {Value: " public" }},
82
+ MethodName: &node.Identifier {Value: " greet" },
83
+ Stmts: []node.Node {
84
+ &stmt.Echo {
85
+ Exprs: []node.Node {
86
+ &scalar.String {Value: " 'Hello world'" },
87
+ },
88
+ },
89
+ },
90
+ },
91
+ },
92
+ },
93
+ },
94
+ }
95
+
96
+ file := os.Stdout
97
+ p := printer.NewPrinter (file, " " )
98
+ p.PrintFile (nodes)
99
+ ```
100
+
101
+ Output:
102
+ ``` PHP
103
+ <?php
104
+ namespace Foo;
105
+ abstract class Bar extends Baz
106
+ {
107
+ public function greet()
108
+ {
109
+ echo 'Hello world';
110
+ }
111
+ }
112
+ ```
113
+
67
114
## Roadmap
68
115
- [X] Lexer
69
116
- [x] PHP 7 syntax analyzer
@@ -75,9 +122,9 @@ It does not change AST but collects resolved names into `map[node.Node]string`
75
122
- [x] PHP 5 syntax analyzer
76
123
- [x] Tests
77
124
- [x] Namespace resolver
125
+ - [x] Pretty printer
78
126
- [ ] PhpDocComment parser
79
127
- [ ] Error handling
80
128
- [ ] Stabilize api
81
129
- [ ] Documentation
82
- - [ ] Pretty printer
83
130
- [ ] Code flow graph
0 commit comments