printer

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 11 Imported by: 0

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
    }
}

func NewPrinter

func NewPrinter(w io.Writer) *Printer

NewPrinter - Constructor for Printer

func (*Printer) Print

func (p *Printer) Print(n node.Node)

func (*Printer) SetState added in v0.6.0

func (p *Printer) SetState(s printerState)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL