[refactoring] update printer

This commit is contained in:
Vadym Slizov 2020-12-11 09:54:26 +02:00
parent f3a605aba1
commit 497e7f82ee
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
10 changed files with 2285 additions and 3649 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -264,6 +264,8 @@ import (
start: start:
top_statement_list top_statement_list
{ {
yylex.(*Parser).currentToken.Value = nil
yylex.(*Parser).rootNode = &ast.Root{ yylex.(*Parser).rootNode = &ast.Root{
Position: yylex.(*Parser).builder.NewNodeListPosition($1), Position: yylex.(*Parser).builder.NewNodeListPosition($1),
Stmts: $1, Stmts: $1,
@ -934,7 +936,6 @@ unticked_statement:
{ {
$2.(*ast.StmtGlobal).GlobalTkn = $1 $2.(*ast.StmtGlobal).GlobalTkn = $1
$2.(*ast.StmtGlobal).SemiColonTkn = $3 $2.(*ast.StmtGlobal).SemiColonTkn = $3
$2.(*ast.StmtGlobal).SeparatorTkns = append($2.(*ast.StmtGlobal).SeparatorTkns, nil)
$2.(*ast.StmtGlobal).Position = yylex.(*Parser).builder.NewTokensPosition($1, $3) $2.(*ast.StmtGlobal).Position = yylex.(*Parser).builder.NewTokensPosition($1, $3)
$$ = $2 $$ = $2
@ -943,7 +944,6 @@ unticked_statement:
{ {
$2.(*ast.StmtStatic).StaticTkn = $1 $2.(*ast.StmtStatic).StaticTkn = $1
$2.(*ast.StmtStatic).SemiColonTkn = $3 $2.(*ast.StmtStatic).SemiColonTkn = $3
$2.(*ast.StmtStatic).SeparatorTkns = append($2.(*ast.StmtStatic).SeparatorTkns, nil)
$2.(*ast.StmtStatic).Position = yylex.(*Parser).builder.NewTokensPosition($1, $3) $2.(*ast.StmtStatic).Position = yylex.(*Parser).builder.NewTokensPosition($1, $3)
$$ = $2 $$ = $2
@ -1069,8 +1069,8 @@ unticked_statement:
GotoTkn: $1, GotoTkn: $1,
Label: &ast.Identifier{ Label: &ast.Identifier{
Position: yylex.(*Parser).builder.NewTokenPosition($1), Position: yylex.(*Parser).builder.NewTokenPosition($1),
IdentifierTkn: $1, IdentifierTkn: $2,
Value: $1.Value, Value: $2.Value,
}, },
SemiColonTkn: $3, SemiColonTkn: $3,
} }
@ -2197,9 +2197,9 @@ trait_adaptations:
{ {
$$ = &ast.StmtTraitAdaptationList{ $$ = &ast.StmtTraitAdaptationList{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenParenthesisTkn: $1, OpenCurlyBracketTkn: $1,
Adaptations: $2, Adaptations: $2,
CloseParenthesisTkn: $3, CloseCurlyBracketTkn: $3,
} }
} }
; ;
@ -2691,7 +2691,7 @@ new_expr:
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments, Arguments: $3.(*ast.ArgumentList).Arguments,
SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $3.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} else { } else {
$$ = &ast.ExprNew{ $$ = &ast.ExprNew{
@ -2749,7 +2749,7 @@ expr_without_variable:
OpenParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $6.(*ast.ArgumentList).Arguments, Arguments: $6.(*ast.ArgumentList).Arguments,
SeparatorTkns: $6.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $6.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $6.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $6.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} else { } else {
_new = &ast.ExprNew{ _new = &ast.ExprNew{
@ -3620,7 +3620,7 @@ function_call:
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| T_NAMESPACE T_NS_SEPARATOR namespace_name function_call_parameter_list | T_NAMESPACE T_NS_SEPARATOR namespace_name function_call_parameter_list
@ -3637,7 +3637,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| T_NS_SEPARATOR namespace_name function_call_parameter_list | T_NS_SEPARATOR namespace_name function_call_parameter_list
@ -3653,7 +3653,7 @@ function_call:
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments, Arguments: $3.(*ast.ArgumentList).Arguments,
SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $3.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list | class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
@ -3666,7 +3666,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects function_call_parameter_list | class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects function_call_parameter_list
@ -3679,7 +3679,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list | variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
@ -3692,7 +3692,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects function_call_parameter_list | variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects function_call_parameter_list
@ -3705,7 +3705,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| variable_without_objects function_call_parameter_list | variable_without_objects function_call_parameter_list
@ -3716,7 +3716,7 @@ function_call:
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
; ;
@ -4500,7 +4500,7 @@ scalar:
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenQoteTkn: $1, OpenQoteTkn: $1,
Parts: $2, Parts: $2,
CloseQoteTkn: $1, CloseQoteTkn: $3,
} }
} }
| T_START_HEREDOC encaps_list T_END_HEREDOC | T_START_HEREDOC encaps_list T_END_HEREDOC
@ -4674,7 +4674,7 @@ variable:
OpenParenthesisTkn: mc.OpenParenthesisTkn, OpenParenthesisTkn: mc.OpenParenthesisTkn,
Arguments: mc.Arguments, Arguments: mc.Arguments,
SeparatorTkns: mc.SeparatorTkns, SeparatorTkns: mc.SeparatorTkns,
CloseParenthesisTkn: mc.OpenParenthesisTkn, CloseParenthesisTkn: mc.CloseParenthesisTkn,
}, },
) )
$3 = append($3, $4[1:len($4)]...) $3 = append($3, $4[1:len($4)]...)

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -281,6 +281,8 @@ import (
start: start:
top_statement_list top_statement_list
{ {
yylex.(*Parser).currentToken.Value = nil
yylex.(*Parser).rootNode = &ast.Root{ yylex.(*Parser).rootNode = &ast.Root{
Position: yylex.(*Parser).builder.NewNodeListPosition($1), Position: yylex.(*Parser).builder.NewNodeListPosition($1),
Stmts: $1, Stmts: $1,
@ -579,7 +581,9 @@ group_use_declaration:
mixed_group_use_declaration: mixed_group_use_declaration:
namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
{ {
$4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5) if $5 != nil {
$4.(*ast.ParserSeparatedList).SeparatorTkns = append($4.(*ast.ParserSeparatedList).SeparatorTkns, $5)
}
$$ = &ast.StmtGroupUse{ $$ = &ast.StmtGroupUse{
Position: yylex.(*Parser).builder.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6), Position: yylex.(*Parser).builder.NewNodeListTokenPosition($1.(*ast.ParserSeparatedList).Items, $6),
@ -597,7 +601,9 @@ mixed_group_use_declaration:
} }
| T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}' | T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
{ {
$5.(*ast.ParserSeparatedList).SeparatorTkns = append($5.(*ast.ParserSeparatedList).SeparatorTkns, $6) if $6 != nil {
$5.(*ast.ParserSeparatedList).SeparatorTkns = append($5.(*ast.ParserSeparatedList).SeparatorTkns, $6)
}
$$ = &ast.StmtGroupUse{ $$ = &ast.StmtGroupUse{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $7), Position: yylex.(*Parser).builder.NewTokensPosition($1, $7),
@ -941,7 +947,9 @@ statement:
{ {
$3.(*ast.StmtUnset).UnsetTkn = $1 $3.(*ast.StmtUnset).UnsetTkn = $1
$3.(*ast.StmtUnset).OpenParenthesisTkn = $2 $3.(*ast.StmtUnset).OpenParenthesisTkn = $2
$3.(*ast.StmtUnset).SeparatorTkns = append($3.(*ast.StmtUnset).SeparatorTkns, $4) if $4 != nil {
$3.(*ast.StmtUnset).SeparatorTkns = append($3.(*ast.StmtUnset).SeparatorTkns, $4)
}
$3.(*ast.StmtUnset).CloseParenthesisTkn = $5 $3.(*ast.StmtUnset).CloseParenthesisTkn = $5
$3.(*ast.StmtUnset).SemiColonTkn = $6 $3.(*ast.StmtUnset).SemiColonTkn = $6
$3.(*ast.StmtUnset).Position = yylex.(*Parser).builder.NewTokensPosition($1, $6) $3.(*ast.StmtUnset).Position = yylex.(*Parser).builder.NewTokensPosition($1, $6)
@ -1815,7 +1823,9 @@ argument_list:
argumentList := $2.(*ast.ArgumentList) argumentList := $2.(*ast.ArgumentList)
argumentList.Position = yylex.(*Parser).builder.NewTokensPosition($1, $4) argumentList.Position = yylex.(*Parser).builder.NewTokensPosition($1, $4)
argumentList.OpenParenthesisTkn = $1 argumentList.OpenParenthesisTkn = $1
argumentList.SeparatorTkns = append(argumentList.SeparatorTkns, $3) if $3 != nil {
argumentList.SeparatorTkns = append(argumentList.SeparatorTkns, $3)
}
argumentList.CloseParenthesisTkn = $4 argumentList.CloseParenthesisTkn = $4
$$ = argumentList $$ = argumentList
@ -2029,17 +2039,17 @@ trait_adaptations:
{ {
$$ = &ast.StmtTraitAdaptationList{ $$ = &ast.StmtTraitAdaptationList{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $2), Position: yylex.(*Parser).builder.NewTokensPosition($1, $2),
OpenParenthesisTkn: $1, OpenCurlyBracketTkn: $1,
CloseParenthesisTkn: $2, CloseCurlyBracketTkn: $2,
} }
} }
| '{' trait_adaptation_list '}' | '{' trait_adaptation_list '}'
{ {
$$ = &ast.StmtTraitAdaptationList{ $$ = &ast.StmtTraitAdaptationList{
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenParenthesisTkn: $1, OpenCurlyBracketTkn: $1,
Adaptations: $2, Adaptations: $2,
CloseParenthesisTkn: $3, CloseCurlyBracketTkn: $3,
} }
} }
; ;
@ -2435,7 +2445,7 @@ anonymous_class:
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
Extends: $3, Extends: $3,
Implements: $4, Implements: $4,
OpenCurlyBracket: $6, OpenCurlyBracket: $6,
@ -2456,7 +2466,7 @@ new_expr:
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments, Arguments: $3.(*ast.ArgumentList).Arguments,
SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $3.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $3.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} else { } else {
$$ = &ast.ExprNew{ $$ = &ast.ExprNew{
@ -3284,7 +3294,7 @@ function_call:
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list | class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
@ -3297,7 +3307,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list | variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
@ -3310,7 +3320,7 @@ function_call:
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments, Arguments: $4.(*ast.ArgumentList).Arguments,
SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $4.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $4.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
| callable_expr argument_list | callable_expr argument_list
@ -3321,7 +3331,7 @@ function_call:
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments, Arguments: $2.(*ast.ArgumentList).Arguments,
SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns, SeparatorTkns: $2.(*ast.ArgumentList).SeparatorTkns,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn, CloseParenthesisTkn: $2.(*ast.ArgumentList).CloseParenthesisTkn,
} }
} }
; ;
@ -3542,7 +3552,7 @@ scalar:
Position: yylex.(*Parser).builder.NewTokensPosition($1, $3), Position: yylex.(*Parser).builder.NewTokensPosition($1, $3),
OpenQoteTkn: $1, OpenQoteTkn: $1,
Parts: $2, Parts: $2,
CloseQoteTkn: $1, CloseQoteTkn: $3,
} }
} }
| T_START_HEREDOC encaps_list T_END_HEREDOC | T_START_HEREDOC encaps_list T_END_HEREDOC

View File

@ -954,10 +954,10 @@ func (n *StmtTrait) GetPosition() *position.Position {
// StmtTraitAdaptationList node // StmtTraitAdaptationList node
type StmtTraitAdaptationList struct { type StmtTraitAdaptationList struct {
Position *position.Position Position *position.Position
OpenParenthesisTkn *token.Token OpenCurlyBracketTkn *token.Token
Adaptations []Vertex Adaptations []Vertex
CloseParenthesisTkn *token.Token CloseCurlyBracketTkn *token.Token
} }
func (n *StmtTraitAdaptationList) Accept(v NodeVisitor) { func (n *StmtTraitAdaptationList) Accept(v NodeVisitor) {

1239
pkg/ast/visitor/printer.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,14 @@
package printer_test package visitor_test
import ( import (
"bytes" "bytes"
"github.com/z7zmey/php-parser/pkg/ast/visitor"
"testing" "testing"
"github.com/z7zmey/php-parser/pkg/ast" "github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/internal/php5" "github.com/z7zmey/php-parser/internal/php5"
"github.com/z7zmey/php-parser/internal/scanner" "github.com/z7zmey/php-parser/internal/scanner"
"github.com/z7zmey/php-parser/pkg/printer"
) )
func parsePhp5(src string) ast.Vertex { func parsePhp5(src string) ast.Vertex {
@ -22,8 +22,8 @@ func parsePhp5(src string) ast.Vertex {
func printPhp5(n ast.Vertex) string { func printPhp5(n ast.Vertex) string {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")
p := printer.NewPrinter(o) printer := visitor.NewPrinter(o)
p.Print(n) n.Accept(printer)
return o.String() return o.String()
} }

View File

@ -1,15 +1,14 @@
package printer_test package visitor_test
import ( import (
"bytes" "bytes"
"os" "os"
"testing" "testing"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/internal/php7" "github.com/z7zmey/php-parser/internal/php7"
"github.com/z7zmey/php-parser/internal/scanner" "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() { func ExamplePrinter() {
@ -42,8 +41,8 @@ abstract class Bar extends Baz
// print // print
p := printer.NewPrinter(os.Stdout) printer := visitor.NewPrinter(os.Stdout)
p.Print(rootNode) rootNode.Accept(printer)
// Output: // Output:
//<?php //<?php
@ -71,8 +70,8 @@ func parse(src string) ast.Vertex {
func print(n ast.Vertex) string { func print(n ast.Vertex) string {
o := bytes.NewBufferString("") o := bytes.NewBufferString("")
p := printer.NewPrinter(o) printer := visitor.NewPrinter(o)
p.Print(n) n.Accept(printer)
return o.String() return o.String()
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff