refactor printer
This commit is contained in:
@@ -27,7 +27,7 @@ func NewNamespaceResolver() *NamespaceResolver {
|
||||
|
||||
func (nsr *NamespaceResolver) EnterNode(n ast.Vertex) bool {
|
||||
n.Accept(nsr)
|
||||
|
||||
|
||||
if !nsr.goDeep {
|
||||
nsr.goDeep = true
|
||||
return false
|
||||
@@ -54,7 +54,7 @@ func (nsr *NamespaceResolver) StmtUseList(n *ast.StmtUseList) {
|
||||
for _, nn := range n.Uses {
|
||||
nsr.AddAlias(useType, nn, nil)
|
||||
}
|
||||
|
||||
|
||||
nsr.goDeep = false
|
||||
}
|
||||
|
||||
|
||||
@@ -194,8 +194,8 @@ func TestResolveInstanceCatch(t *testing.T) {
|
||||
nameBC,
|
||||
nameF,
|
||||
},
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
Stmts: []ast.Vertex{},
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
Stmts: []ast.Vertex{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -407,7 +407,7 @@ func TestResolveClassName(t *testing.T) {
|
||||
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
|
||||
|
||||
class := &ast.StmtClass{
|
||||
ClassName: &ast.Identifier{Value: []byte("A")},
|
||||
ClassName: &ast.Identifier{Value: []byte("A")},
|
||||
Extends: &ast.StmtClassExtends{
|
||||
ClassName: nameAB,
|
||||
},
|
||||
@@ -472,8 +472,8 @@ func TestResolveInterfaceName(t *testing.T) {
|
||||
|
||||
func TestResolveTraitName(t *testing.T) {
|
||||
traitNode := &ast.StmtTrait{
|
||||
TraitName: &ast.Identifier{Value: []byte("A")},
|
||||
Stmts: []ast.Vertex{},
|
||||
TraitName: &ast.Identifier{Value: []byte("A")},
|
||||
Stmts: []ast.Vertex{},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
@@ -498,14 +498,14 @@ func TestResolveFunctionName(t *testing.T) {
|
||||
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
|
||||
|
||||
functionNode := &ast.StmtFunction{
|
||||
ReturnsRef: false,
|
||||
FunctionName: &ast.Identifier{Value: []byte("A")},
|
||||
ReturnsRef: false,
|
||||
FunctionName: &ast.Identifier{Value: []byte("A")},
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
},
|
||||
},
|
||||
ReturnType: &ast.Nullable{Expr: nameBC},
|
||||
@@ -536,14 +536,14 @@ func TestResolveMethodName(t *testing.T) {
|
||||
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
|
||||
|
||||
methodNode := &ast.StmtClassMethod{
|
||||
ReturnsRef: false,
|
||||
MethodName: &ast.Identifier{Value: []byte("A")},
|
||||
ReturnsRef: false,
|
||||
MethodName: &ast.Identifier{Value: []byte("A")},
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
},
|
||||
},
|
||||
ReturnType: &ast.Nullable{Expr: nameBC},
|
||||
@@ -569,14 +569,14 @@ func TestResolveClosureName(t *testing.T) {
|
||||
nameBC := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("B")}, &ast.NameNamePart{Value: []byte("C")}}}
|
||||
|
||||
closureNode := &ast.ExprClosure{
|
||||
ReturnsRef: false,
|
||||
Static: false,
|
||||
ReturnsRef: false,
|
||||
Static: false,
|
||||
Params: []ast.Vertex{
|
||||
&ast.Parameter{
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
ByRef: false,
|
||||
Variadic: false,
|
||||
Type: nameAB,
|
||||
Var: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("foo")}},
|
||||
},
|
||||
},
|
||||
ClosureUse: nil,
|
||||
@@ -600,12 +600,12 @@ func TestResolveConstantsName(t *testing.T) {
|
||||
nameAB := &ast.NameName{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("A")}, &ast.NameNamePart{Value: []byte("B")}}}
|
||||
|
||||
constantB := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
ConstantName: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
constantC := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
ConstantName: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
@@ -644,12 +644,12 @@ func TestResolveNamespaces(t *testing.T) {
|
||||
relativeNameCE := &ast.NameRelative{Parts: []ast.Vertex{&ast.NameNamePart{Value: []byte("C")}, &ast.NameNamePart{Value: []byte("E")}}}
|
||||
|
||||
constantB := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
ConstantName: &ast.Identifier{Value: []byte("B")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
constantC := &ast.StmtConstant{
|
||||
ConstantName: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
ConstantName: &ast.Identifier{Value: []byte("C")},
|
||||
Expr: &ast.ScalarLnumber{Value: []byte("1")},
|
||||
}
|
||||
|
||||
stxTree := &ast.StmtStmtList{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+11
-2
@@ -2,8 +2,6 @@ package token
|
||||
|
||||
type Position int
|
||||
|
||||
type Collection map[Position][]Token
|
||||
|
||||
//go:generate stringer -type=Position -output ./position_string.go
|
||||
const (
|
||||
Start Position = iota
|
||||
@@ -86,3 +84,14 @@ const (
|
||||
OpenParenthesisToken
|
||||
CloseParenthesisToken
|
||||
)
|
||||
|
||||
type Collection map[Position][]Token
|
||||
|
||||
func (c Collection) IsEmpty() bool {
|
||||
for _, v := range c {
|
||||
if len(v) > 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user