Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( PhpState printerState = iota HtmlState )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrettyPrinter ¶ added in v0.6.0
type PrettyPrinter struct {
// contains filtered or unexported fields
}
func NewPrettyPrinter ¶ added in v0.6.0
func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter
NewPrettyPrinter - Constructor for PrettyPrinter
func (*PrettyPrinter) Print ¶ added in v0.6.0
func (p *PrettyPrinter) Print(n node.Node)
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "bytes" "os" "github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node/name" "github.com/z7zmey/php-parser/node/stmt" "github.com/z7zmey/php-parser/php7" "github.com/z7zmey/php-parser/printer" ) func main() { src := `<?php namespace Foo; abstract class Bar extends Baz { public function greet() { echo "Hello"; // some comment } } ` // parse php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser.WithFreeFloating() php7parser.Parse() rootNode := php7parser.GetRootNode() // change namespace parts := &rootNode.(*node.Root).Stmts[0].(*stmt.Namespace).NamespaceName.(*name.Name).Parts *parts = append(*parts, &name.NamePart{Value: "Quuz"}) // print p := printer.NewPrinter(os.Stdout) p.Print(rootNode) }
Output: <?php namespace Foo\Quuz; abstract class Bar extends Baz { public function greet() { echo "Hello"; // some comment } }
Click to show internal directories.
Click to hide internal directories.