printer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 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/VKCOM/noverify/src/php/parser/node/name"
	"github.com/VKCOM/noverify/src/php/parser/node/stmt"
	"github.com/VKCOM/noverify/src/php/parser/php7"
	"github.com/VKCOM/noverify/src/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([]byte(src))
	php7parser.WithFreeFloating()
	php7parser.Parse()

	rootNode := php7parser.GetRootNode()

	// change namespace

	parts := &rootNode.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