[refactoring] update ast structure of "name" nodes
This commit is contained in:
@@ -603,8 +603,12 @@ func (n *StmtLabel) Accept(v NodeVisitor) {
|
||||
// StmtNamespace node
|
||||
type StmtNamespace struct {
|
||||
Node
|
||||
NamespaceName Vertex
|
||||
Stmts []Vertex
|
||||
NsTkn *token.Token
|
||||
Name Vertex
|
||||
OpenCurlyBracket *token.Token
|
||||
Stmts []Vertex
|
||||
CloseCurlyBracket *token.Token
|
||||
SemiColonTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *StmtNamespace) Accept(v NodeVisitor) {
|
||||
@@ -1840,7 +1844,8 @@ func (n *ExprBinarySpaceship) Accept(v NodeVisitor) {
|
||||
|
||||
type NameName struct {
|
||||
Node
|
||||
Parts []Vertex
|
||||
Parts []Vertex
|
||||
ListSeparatorTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *NameName) Accept(v NodeVisitor) {
|
||||
@@ -1849,7 +1854,9 @@ func (n *NameName) Accept(v NodeVisitor) {
|
||||
|
||||
type NameFullyQualified struct {
|
||||
Node
|
||||
Parts []Vertex
|
||||
NsSeparatorTkn *token.Token
|
||||
Parts []Vertex
|
||||
ListSeparatorTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *NameFullyQualified) Accept(v NodeVisitor) {
|
||||
@@ -1858,7 +1865,10 @@ func (n *NameFullyQualified) Accept(v NodeVisitor) {
|
||||
|
||||
type NameRelative struct {
|
||||
Node
|
||||
Parts []Vertex
|
||||
NsTkn *token.Token
|
||||
NsSeparatorTkn *token.Token
|
||||
Parts []Vertex
|
||||
ListSeparatorTkn *token.Token
|
||||
}
|
||||
|
||||
func (n *NameRelative) Accept(v NodeVisitor) {
|
||||
@@ -1867,7 +1877,9 @@ func (n *NameRelative) Accept(v NodeVisitor) {
|
||||
|
||||
type NameNamePart struct {
|
||||
Node
|
||||
Value []byte
|
||||
NsSeparatorTkn *token.Token
|
||||
StringTkn *token.Token
|
||||
Value []byte
|
||||
}
|
||||
|
||||
func (n *NameNamePart) Accept(v NodeVisitor) {
|
||||
|
||||
@@ -845,10 +845,10 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
||||
if !t.visitor.EnterNode(nn) {
|
||||
return
|
||||
}
|
||||
if nn.NamespaceName != nil {
|
||||
t.visitor.Enter("NamespaceName", true)
|
||||
t.Traverse(nn.NamespaceName)
|
||||
t.visitor.Leave("NamespaceName", true)
|
||||
if nn.Name != nil {
|
||||
t.visitor.Enter("Name", true)
|
||||
t.Traverse(nn.Name)
|
||||
t.visitor.Leave("Name", true)
|
||||
}
|
||||
if nn.Stmts != nil {
|
||||
t.visitor.Enter("Stmts", false)
|
||||
|
||||
@@ -33,3 +33,30 @@ func (v *FilterTokens) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
|
||||
n.AsTkn = nil
|
||||
n.CommaTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) NameNamePart(n *ast.NameNamePart) {
|
||||
n.NsSeparatorTkn = nil
|
||||
n.StringTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) NameName(n *ast.NameName) {
|
||||
n.ListSeparatorTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) NameFullyQualified(n *ast.NameFullyQualified) {
|
||||
n.NsSeparatorTkn = nil
|
||||
n.ListSeparatorTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) NameRelative(n *ast.NameRelative) {
|
||||
n.NsTkn = nil
|
||||
n.NsSeparatorTkn = nil
|
||||
n.ListSeparatorTkn = nil
|
||||
}
|
||||
|
||||
func (v *FilterTokens) StmtNamespace(n *ast.StmtNamespace) {
|
||||
n.NsTkn = nil
|
||||
n.OpenCurlyBracket = nil
|
||||
n.CloseCurlyBracket = nil
|
||||
n.SemiColonTkn = nil
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ func (nsr *NamespaceResolver) EnterNode(n ast.Vertex) bool {
|
||||
}
|
||||
|
||||
func (nsr *NamespaceResolver) StmtNamespace(n *ast.StmtNamespace) {
|
||||
if n.NamespaceName == nil {
|
||||
if n.Name == nil {
|
||||
nsr.Namespace = NewNamespace("")
|
||||
} else {
|
||||
NSParts := n.NamespaceName.(*ast.NameName).Parts
|
||||
NSParts := n.Name.(*ast.NameName).Parts
|
||||
nsr.Namespace = NewNamespace(concatNameParts(NSParts))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +605,7 @@ func TestResolveConstantsName(t *testing.T) {
|
||||
stxTree := &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: nameAB,
|
||||
Name: nameAB,
|
||||
},
|
||||
&ast.StmtConstList{
|
||||
Consts: []ast.Vertex{
|
||||
@@ -649,7 +649,7 @@ func TestResolveNamespaces(t *testing.T) {
|
||||
stxTree := &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: namespaceAB,
|
||||
Name: namespaceAB,
|
||||
},
|
||||
&ast.StmtConstList{
|
||||
Consts: []ast.Vertex{
|
||||
@@ -666,7 +666,7 @@ func TestResolveNamespaces(t *testing.T) {
|
||||
Stmts: []ast.Vertex{},
|
||||
},
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: namespaceCD,
|
||||
Name: namespaceCD,
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtUse{
|
||||
UseDeclarations: []ast.Vertex{
|
||||
@@ -749,7 +749,7 @@ func TestDoNotResolveReservedConstants(t *testing.T) {
|
||||
stxTree := &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: namespaceName,
|
||||
Name: namespaceName,
|
||||
},
|
||||
&ast.StmtExpression{
|
||||
Expr: &ast.ExprConstFetch{
|
||||
@@ -877,7 +877,7 @@ func TestDoNotResolveReservedNames(t *testing.T) {
|
||||
stxTree := &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{Value: []byte("Foo")},
|
||||
},
|
||||
@@ -955,7 +955,7 @@ func TestDoNotResolveReservedSpecialNames(t *testing.T) {
|
||||
stxTree := &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{Value: []byte("Foo")},
|
||||
},
|
||||
@@ -1007,7 +1007,7 @@ func TestResolvePropertyTypeName(t *testing.T) {
|
||||
stmts := &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{Value: []byte("Foo")},
|
||||
},
|
||||
|
||||
@@ -1931,9 +1931,9 @@ func (p *PrettyPrinter) printStmtNamespace(n ast.Vertex) {
|
||||
|
||||
io.WriteString(p.w, "namespace")
|
||||
|
||||
if nn.NamespaceName != nil {
|
||||
if nn.Name != nil {
|
||||
io.WriteString(p.w, " ")
|
||||
p.Print(nn.NamespaceName)
|
||||
p.Print(nn.Name)
|
||||
}
|
||||
|
||||
if nn.Stmts != nil {
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class Bar extends Baz
|
||||
rootNode := &ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{Value: []byte("Foo")},
|
||||
},
|
||||
@@ -3454,7 +3454,7 @@ func TestPrintNamespace(t *testing.T) {
|
||||
|
||||
p := printer.NewPrettyPrinter(o, " ")
|
||||
p.Print(&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Name: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
})
|
||||
|
||||
expected := `namespace Foo;`
|
||||
@@ -3472,7 +3472,7 @@ func TestPrintNamespaceWithStmts(t *testing.T) {
|
||||
p.Print(&ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Name: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtExpression{Expr: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("a")}}},
|
||||
},
|
||||
|
||||
@@ -55,6 +55,16 @@ func (p *Printer) joinPrint(glue string, nn []ast.Vertex) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Printer) joinPrintRefactored(glue string, nn []ast.Vertex) {
|
||||
for k, n := range nn {
|
||||
if k > 0 {
|
||||
p.bufStart = glue
|
||||
}
|
||||
|
||||
p.Print(n)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Printer) printNodes(nn []ast.Vertex) {
|
||||
for _, n := range nn {
|
||||
p.Print(n)
|
||||
@@ -558,50 +568,36 @@ func (p *Printer) printNodeArgument(n ast.Vertex) {
|
||||
|
||||
// name
|
||||
|
||||
func (p *Printer) printNameNamePart(n ast.Vertex) {
|
||||
nn := n.(*ast.NameNamePart)
|
||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
||||
p.bufStart = ""
|
||||
|
||||
io.WriteString(p.w, string(nn.Value))
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
func (p *Printer) printNameNamePart(n *ast.NameNamePart) {
|
||||
p.printToken(n.NsSeparatorTkn, "")
|
||||
p.printToken(n.StringTkn, string(n.Value))
|
||||
}
|
||||
|
||||
func (p *Printer) printNameName(n ast.Vertex) {
|
||||
nn := n.(*ast.NameName)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
func (p *Printer) printNameName(n *ast.NameName) {
|
||||
p.printFreeFloating(n, token.Start)
|
||||
|
||||
p.joinPrint("\\", nn.Parts)
|
||||
p.joinPrintRefactored("\\", n.Parts)
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.printToken(n.ListSeparatorTkn, "")
|
||||
}
|
||||
|
||||
func (p *Printer) printNameFullyQualified(n ast.Vertex) {
|
||||
nn := n.(*ast.NameFullyQualified)
|
||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
||||
p.bufStart = ""
|
||||
func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) {
|
||||
p.printFreeFloating(n, token.Start)
|
||||
p.printToken(n.NsSeparatorTkn, "\\")
|
||||
|
||||
io.WriteString(p.w, "\\")
|
||||
p.joinPrint("\\", nn.Parts)
|
||||
p.joinPrintRefactored("\\", n.Parts)
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.printToken(n.ListSeparatorTkn, "")
|
||||
}
|
||||
|
||||
func (p *Printer) printNameRelative(n ast.Vertex) {
|
||||
nn := n.(*ast.NameRelative)
|
||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
||||
p.bufStart = ""
|
||||
func (p *Printer) printNameRelative(n *ast.NameRelative) {
|
||||
p.printFreeFloating(n, token.Start)
|
||||
p.printToken(n.NsTkn, "namespace")
|
||||
p.printToken(n.NsSeparatorTkn, "\\")
|
||||
|
||||
io.WriteString(p.w, "namespace")
|
||||
p.printFreeFloating(nn, token.Namespace)
|
||||
p.joinPrintRefactored("\\", n.Parts)
|
||||
|
||||
for _, part := range nn.Parts {
|
||||
io.WriteString(p.w, "\\")
|
||||
p.Print(part)
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.printToken(n.ListSeparatorTkn, "")
|
||||
}
|
||||
|
||||
// scalar
|
||||
@@ -2299,7 +2295,9 @@ func (p *Printer) printStmtCatch(n ast.Vertex) {
|
||||
io.WriteString(p.w, "catch")
|
||||
p.printFreeFloating(nn, token.Catch)
|
||||
io.WriteString(p.w, "(")
|
||||
p.joinPrint("|", nn.Types)
|
||||
|
||||
p.joinPrintRefactored("|", nn.Types)
|
||||
|
||||
p.Print(nn.Var)
|
||||
p.printFreeFloating(nn, token.Var)
|
||||
io.WriteString(p.w, ")")
|
||||
@@ -2409,10 +2407,9 @@ func (p *Printer) printStmtClass(n ast.Vertex) {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
io.WriteString(p.w, "implements")
|
||||
if nn.Implements.InterfaceNames[0].GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
p.joinPrint(",", nn.Implements.InterfaceNames)
|
||||
p.bufStart = " "
|
||||
p.joinPrintRefactored(",", nn.Implements.InterfaceNames)
|
||||
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.Name)
|
||||
@@ -2896,10 +2893,8 @@ func (p *Printer) printStmtInterface(n ast.Vertex) {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
io.WriteString(p.w, "extends")
|
||||
if nn.Extends.InterfaceNames[0].GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
p.joinPrint(",", nn.Extends.InterfaceNames)
|
||||
p.bufStart = " "
|
||||
p.joinPrintRefactored(",", nn.Extends.InterfaceNames)
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.Name)
|
||||
@@ -2923,32 +2918,28 @@ func (p *Printer) printStmtLabel(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtNamespace(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtNamespace)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
io.WriteString(p.w, "namespace")
|
||||
func (p *Printer) printStmtNamespace(n *ast.StmtNamespace) {
|
||||
p.printToken(n.NsTkn, "namespace")
|
||||
|
||||
if nn.NamespaceName != nil {
|
||||
if nn.NamespaceName.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
p.Print(nn.NamespaceName)
|
||||
if n.Name != nil {
|
||||
p.bufStart = " "
|
||||
p.Print(n.Name)
|
||||
}
|
||||
|
||||
if nn.Stmts != nil {
|
||||
p.printFreeFloating(nn, token.Namespace)
|
||||
io.WriteString(p.w, "{")
|
||||
p.printNodes(nn.Stmts)
|
||||
p.printFreeFloating(nn, token.Stmts)
|
||||
io.WriteString(p.w, "}")
|
||||
} else {
|
||||
p.printFreeFloating(nn, token.SemiColon)
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, ";")
|
||||
}
|
||||
if n.Stmts != nil {
|
||||
p.printToken(n.OpenCurlyBracket, "{")
|
||||
p.printNodes(n.Stmts)
|
||||
p.printToken(n.CloseCurlyBracket, "}")
|
||||
return
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
if n.OpenCurlyBracket != nil {
|
||||
p.printToken(n.OpenCurlyBracket, "{")
|
||||
p.printToken(n.CloseCurlyBracket, "}")
|
||||
return
|
||||
}
|
||||
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtNop(n ast.Vertex) {
|
||||
@@ -3202,10 +3193,8 @@ func (p *Printer) printStmtTraitUse(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
|
||||
io.WriteString(p.w, "use")
|
||||
if nn.Traits[0].GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
p.joinPrint(",", nn.Traits)
|
||||
p.bufStart = " "
|
||||
p.joinPrintRefactored(",", nn.Traits)
|
||||
|
||||
p.Print(nn.TraitAdaptationList)
|
||||
|
||||
@@ -3276,11 +3265,13 @@ func (p *Printer) printStmtUnset(n ast.Vertex) {
|
||||
func (p *Printer) printStmtUse(n *ast.StmtUse) {
|
||||
p.printToken(n.UseTkn, "use")
|
||||
|
||||
p.bufStart = " "
|
||||
p.Print(n.Type)
|
||||
if n.Type != nil {
|
||||
p.bufStart = " "
|
||||
p.Print(n.Type)
|
||||
}
|
||||
|
||||
p.bufStart = " "
|
||||
p.joinPrint(",", n.UseDeclarations)
|
||||
p.joinPrintRefactored(",", n.UseDeclarations)
|
||||
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
@@ -3298,16 +3289,7 @@ func (p *Printer) printStmtGroupUse(n *ast.StmtGroupUse) {
|
||||
p.printToken(n.NsSeparatorTkn, "\\")
|
||||
p.printToken(n.OpenCurlyBracketTkn, "{")
|
||||
|
||||
for k, v := range n.UseDeclarations {
|
||||
p.Print(v)
|
||||
var def string
|
||||
if k != len(n.UseDeclarations)-1 {
|
||||
def = ","
|
||||
}
|
||||
if decl, ok := v.(*ast.StmtUseDeclaration); ok {
|
||||
p.printToken(decl.CommaTkn, def)
|
||||
}
|
||||
}
|
||||
p.joinPrintRefactored(",", n.UseDeclarations)
|
||||
|
||||
p.printToken(n.CloseCurlyBracketTkn, "}")
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
@@ -3325,6 +3307,7 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
|
||||
p.Print(n.Use)
|
||||
|
||||
if n.Alias == nil {
|
||||
p.printToken(n.CommaTkn, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3333,6 +3316,8 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
|
||||
|
||||
p.bufStart = " "
|
||||
p.Print(n.Alias)
|
||||
|
||||
p.printToken(n.CommaTkn, "")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtWhile(n ast.Vertex) {
|
||||
|
||||
@@ -45,8 +45,8 @@ func TestParseAndPrintPhp5Root(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Identifier(t *testing.T) {
|
||||
|
||||
src := `<?
|
||||
// TODO: remove ; after <?php
|
||||
src := `<? ;
|
||||
/* Foo */
|
||||
Foo ( ) ;
|
||||
`
|
||||
@@ -73,8 +73,8 @@ func TestParseAndPrintPhp5Parameter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Argument(t *testing.T) {
|
||||
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo ( $a , $b
|
||||
, $c
|
||||
) ; `
|
||||
@@ -89,7 +89,8 @@ func TestParseAndPrintPhp5Argument(t *testing.T) {
|
||||
// test name
|
||||
|
||||
func TestParseAndPrintPhp5Names(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo ( ) ;
|
||||
\ foo ( ) ;
|
||||
namespace \ foo ( ) ;
|
||||
@@ -168,7 +169,8 @@ func TestParseAndPrintPhp5String(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Heredoc(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo(<<<EAP
|
||||
test
|
||||
EAP
|
||||
@@ -289,7 +291,8 @@ func TestParseAndPrintPhp5Cast(t *testing.T) {
|
||||
// test expr
|
||||
|
||||
func TestParseAndPrintPhp5ArrayDimFetch(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
FOO [ ] ;
|
||||
FOO [ 1 ] ;
|
||||
$a [ ] ;
|
||||
@@ -415,7 +418,8 @@ func TestParseAndPrintPhp5Closure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5ConstFetch(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
null ;
|
||||
`
|
||||
|
||||
@@ -481,7 +485,8 @@ func TestParseAndPrintPhp5Exit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5FunctionCall(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo ( ) ;
|
||||
$var ( $a , ... $b , $c ) ;
|
||||
`
|
||||
@@ -551,7 +556,8 @@ func TestParseAndPrintPhp5MethodCall(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5New(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
|
||||
new Foo ;
|
||||
|
||||
@@ -664,7 +670,8 @@ func TestParseAndPrintPhp5ShortArray(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
Foo :: bar ( $a , $b ) ;`
|
||||
|
||||
actual := printPhp5(parsePhp5(src))
|
||||
@@ -675,7 +682,8 @@ func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5StaticPropertyFetch(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
Foo :: $bar ;`
|
||||
|
||||
actual := printPhp5(parsePhp5(src))
|
||||
@@ -1117,7 +1125,8 @@ func TestParseAndPrintPhp5GotoLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5Namespace(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
namespace Foo \ Bar ;
|
||||
namespace Baz {
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
)
|
||||
|
||||
func ExamplePrinter() {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
|
||||
namespace Foo;
|
||||
|
||||
@@ -37,7 +38,7 @@ abstract class Bar extends Baz
|
||||
|
||||
// change namespace
|
||||
|
||||
parts := &rootNode.(*ast.Root).Stmts[0].(*ast.StmtNamespace).NamespaceName.(*ast.NameName).Parts
|
||||
parts := &rootNode.(*ast.Root).Stmts[1].(*ast.StmtNamespace).Name.(*ast.NameName).Parts
|
||||
*parts = append(*parts, &ast.NameNamePart{Value: []byte("Quuz")})
|
||||
|
||||
// print
|
||||
@@ -46,7 +47,7 @@ abstract class Bar extends Baz
|
||||
p.Print(rootNode)
|
||||
|
||||
// Output:
|
||||
//<?php
|
||||
//<?php ;
|
||||
//
|
||||
// namespace Foo\Quuz;
|
||||
//
|
||||
@@ -94,8 +95,8 @@ func TestParseAndPrintRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintIdentifier(t *testing.T) {
|
||||
|
||||
src := `<?
|
||||
// TODO: remove ; after <?php
|
||||
src := `<? ;
|
||||
/* Foo */
|
||||
Foo ( ) ;
|
||||
`
|
||||
@@ -151,8 +152,8 @@ func TestParseAndPrintNullable(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintArgument(t *testing.T) {
|
||||
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo ( $a , $b
|
||||
, ... $c ,
|
||||
) ; `
|
||||
@@ -167,7 +168,8 @@ func TestParseAndPrintArgument(t *testing.T) {
|
||||
// test name
|
||||
|
||||
func TestParseAndPrintNames(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo ( ) ;
|
||||
\ foo ( ) ;
|
||||
namespace \ foo ( ) ;
|
||||
@@ -246,7 +248,8 @@ func TestParseAndPrintString(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintHeredoc(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo(<<<EAP
|
||||
test
|
||||
EAP
|
||||
@@ -370,7 +373,8 @@ func TestParseAndPrintCast(t *testing.T) {
|
||||
// test expr
|
||||
|
||||
func TestParseAndPrintArrayDimFetch(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
FOO [ ] ;
|
||||
FOO [ 1 ] ;
|
||||
$a [ ] ;
|
||||
@@ -509,7 +513,8 @@ func TestParseAndPrintArrowFunction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintConstFetch(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
null ;
|
||||
`
|
||||
|
||||
@@ -575,7 +580,8 @@ func TestParseAndPrintExit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintFunctionCall(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
foo ( ) ;
|
||||
$var ( $a , ... $b , $c ) ;
|
||||
`
|
||||
@@ -776,7 +782,8 @@ func TestParseAndPrintShortList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintStaticCall(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
Foo :: bar ( $a , $b ) ;`
|
||||
|
||||
actual := print(parse(src))
|
||||
@@ -787,7 +794,8 @@ func TestParseAndPrintStaticCall(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintStaticPropertyFetch(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
Foo :: $bar ;`
|
||||
|
||||
actual := print(parse(src))
|
||||
@@ -1250,7 +1258,8 @@ func TestParseAndPrintGotoLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintNamespace(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
namespace Foo \ Bar ;
|
||||
namespace Baz {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestPrinterPrintFile(t *testing.T) {
|
||||
p.Print(&ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NameNamePart{Value: []byte("Foo")},
|
||||
},
|
||||
@@ -3862,7 +3862,7 @@ func TestPrinterPrintNamespace(t *testing.T) {
|
||||
|
||||
p := printer.NewPrinter(o)
|
||||
p.Print(&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Name: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
})
|
||||
|
||||
expected := `namespace Foo;`
|
||||
@@ -3878,7 +3878,7 @@ func TestPrinterPrintNamespaceWithStmts(t *testing.T) {
|
||||
|
||||
p := printer.NewPrinter(o)
|
||||
p.Print(&ast.StmtNamespace{
|
||||
NamespaceName: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Name: &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("Foo")}}},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtExpression{Expr: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{Value: []byte("$a")},
|
||||
|
||||
Reference in New Issue
Block a user