MCPcopy Create free account
hub / github.com/z7zmey/php-parser / ExamplePrinter

Function ExamplePrinter

printer/printer_parsed_php7_test.go:15–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func ExamplePrinter() {
16 src := `<?php
17
18namespace Foo;
19
20abstract class Bar extends Baz
21{
22 public function greet()
23 {
24 echo "Hello";
25 // some comment
26 }
27}
28 `
29
30 // parse
31
32 php7parser := php7.NewParser([]byte(src), "7.4")
33 php7parser.WithFreeFloating()
34 php7parser.Parse()
35
36 rootNode := php7parser.GetRootNode()
37
38 // change namespace
39
40 parts := &rootNode.(*node.Root).Stmts[0].(*stmt.Namespace).NamespaceName.(*name.Name).Parts
41 *parts = append(*parts, &name.NamePart{Value: "Quuz"})
42
43 // print
44
45 p := printer.NewPrinter(os.Stdout)
46 p.Print(rootNode)
47
48 // Output:
49 //<?php
50 //
51 // namespace Foo\Quuz;
52 //
53 // abstract class Bar extends Baz
54 // {
55 // public function greet()
56 // {
57 // echo "Hello";
58 // // some comment
59 // }
60 // }
61}
62
63func parse(src string) node.Node {
64 php7parser := php7.NewParser([]byte(src), "7.4")

Callers

nothing calls this directly

Calls 6

WithFreeFloatingMethod · 0.95
ParseMethod · 0.95
GetRootNodeMethod · 0.95
PrintMethod · 0.95
NewParserFunction · 0.92
NewPrinterFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…