printer

package
v0.0.0-...-6a25f69 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT, 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

type PrettyPrinter struct {
	// contains filtered or unexported fields
}

func NewPrettyPrinter

func NewPrettyPrinter(w io.Writer, indentStr string) *PrettyPrinter

NewPrettyPrinter - Constructor for PrettyPrinter

func (*PrettyPrinter) Print

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

type Printer

type Printer struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"os"

	"github.com/i582/php2go/src/php/node"
	"github.com/i582/php2go/src/php/node/name"
	"github.com/i582/php2go/src/php/node/stmt"
	"github.com/i582/php2go/src/php/php7"
	"github.com/i582/php2go/src/php/printer"
)

func main() {
	src := `<?php

namespace Foo;

abstract class Bar extends Baz
{
    public function greet()
    {
        echo "Hello";
        // some comment
    }
}
	`

	// parse

	php7parser := php7.NewParser([]byte(src), "7.4")
	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

func (p *Printer) SetState(s printerState)

Jump to

Keyboard shortcuts

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