diff --git a/README.md b/README.md index 5f98e44..1ec37f4 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,53 @@ It does not change AST but collects resolved names into `map[node.Node]string` - For `Class`, `Interface`, `Trait`, `Function`, `ConstList` nodes collects name with current namespace. - For `Name`, `Relative`, `FullyQualified` nodes resolves `use` aliases and collects a fully qualified name. +## Pretty printer + +```Golang +nodes := &stmt.StmtList{ + Stmts: []node.Node{ + &stmt.Namespace{ + NamespaceName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Foo"}}}, + }, + &stmt.Class{ + Modifiers: []node.Node{&node.Identifier{Value: "abstract"}}, + ClassName: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Bar"}}}, + Extends: &name.Name{Parts: []node.Node{&name.NamePart{Value: "Baz"}}}, + Stmts: []node.Node{ + &stmt.ClassMethod{ + Modifiers: []node.Node{&node.Identifier{Value: "public"}}, + MethodName: &node.Identifier{Value: "greet"}, + Stmts: []node.Node{ + &stmt.Echo{ + Exprs: []node.Node{ + &scalar.String{Value: "'Hello world'"}, + }, + }, + }, + }, + }, + }, + }, +} + +file := os.Stdout +p := printer.NewPrinter(file, " ") +p.PrintFile(nodes) +``` + +Output: +```PHP +