[refactoring] update printer
This commit is contained in:
@@ -954,10 +954,10 @@ func (n *StmtTrait) GetPosition() *position.Position {
|
||||
|
||||
// StmtTraitAdaptationList node
|
||||
type StmtTraitAdaptationList struct {
|
||||
Position *position.Position
|
||||
OpenParenthesisTkn *token.Token
|
||||
Adaptations []Vertex
|
||||
CloseParenthesisTkn *token.Token
|
||||
Position *position.Position
|
||||
OpenCurlyBracketTkn *token.Token
|
||||
Adaptations []Vertex
|
||||
CloseCurlyBracketTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtTraitAdaptationList) Accept(v NodeVisitor) {
|
||||
|
||||
1239
pkg/ast/visitor/printer.go
Normal file
1239
pkg/ast/visitor/printer.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,14 @@
|
||||
package printer_test
|
||||
package visitor_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/z7zmey/php-parser/pkg/ast/visitor"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/pkg/ast"
|
||||
|
||||
"github.com/z7zmey/php-parser/internal/php5"
|
||||
"github.com/z7zmey/php-parser/internal/scanner"
|
||||
"github.com/z7zmey/php-parser/pkg/printer"
|
||||
)
|
||||
|
||||
func parsePhp5(src string) ast.Vertex {
|
||||
@@ -22,8 +22,8 @@ func parsePhp5(src string) ast.Vertex {
|
||||
func printPhp5(n ast.Vertex) string {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := printer.NewPrinter(o)
|
||||
p.Print(n)
|
||||
printer := visitor.NewPrinter(o)
|
||||
n.Accept(printer)
|
||||
|
||||
return o.String()
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
package printer_test
|
||||
package visitor_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/pkg/ast"
|
||||
|
||||
"github.com/z7zmey/php-parser/internal/php7"
|
||||
"github.com/z7zmey/php-parser/internal/scanner"
|
||||
"github.com/z7zmey/php-parser/pkg/printer"
|
||||
"github.com/z7zmey/php-parser/pkg/ast"
|
||||
"github.com/z7zmey/php-parser/pkg/ast/visitor"
|
||||
)
|
||||
|
||||
func ExamplePrinter() {
|
||||
@@ -42,8 +41,8 @@ abstract class Bar extends Baz
|
||||
|
||||
// print
|
||||
|
||||
p := printer.NewPrinter(os.Stdout)
|
||||
p.Print(rootNode)
|
||||
printer := visitor.NewPrinter(os.Stdout)
|
||||
rootNode.Accept(printer)
|
||||
|
||||
// Output:
|
||||
//<?php
|
||||
@@ -71,8 +70,8 @@ func parse(src string) ast.Vertex {
|
||||
func print(n ast.Vertex) string {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := printer.NewPrinter(o)
|
||||
p.Print(n)
|
||||
printer := visitor.NewPrinter(o)
|
||||
n.Accept(printer)
|
||||
|
||||
return o.String()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user