[refactoring] update ast structure of "name" nodes
This commit is contained in:
parent
767187ff85
commit
c1b3e6f5b2
@ -8546,7 +8546,7 @@ func TestStmtNamespace(t *testing.T) {
|
|||||||
EndPos: 17,
|
EndPos: 17,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 1,
|
StartLine: 1,
|
||||||
@ -8604,7 +8604,7 @@ func TestStmtNamespace_Stmts(t *testing.T) {
|
|||||||
EndPos: 19,
|
EndPos: 19,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 1,
|
StartLine: 1,
|
||||||
|
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -301,26 +301,26 @@ top_statement_list:
|
|||||||
namespace_name:
|
namespace_name:
|
||||||
T_STRING
|
T_STRING
|
||||||
{
|
{
|
||||||
namePart := &ast.NameNamePart{ast.Node{}, $1.Value}
|
$$ = []ast.Vertex{
|
||||||
$$ = []ast.Vertex{namePart}
|
&ast.NameNamePart{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenPosition($1),
|
||||||
namePart.GetNode().Position = position.NewTokenPosition($1)
|
},
|
||||||
|
StringTkn: $1,
|
||||||
// save comments
|
Value: $1.Value,
|
||||||
yylex.(*Parser).setFreeFloating(namePart, token.Start, $1.SkippedTokens)
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| namespace_name T_NS_SEPARATOR T_STRING
|
| namespace_name T_NS_SEPARATOR T_STRING
|
||||||
{
|
{
|
||||||
namePart := &ast.NameNamePart{ast.Node{}, $3.Value}
|
$$ = append($1, &ast.NameNamePart{
|
||||||
$$ = append($1, namePart)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($2, $3),
|
||||||
// save position
|
},
|
||||||
namePart.GetNode().Position = position.NewTokenPosition($3)
|
NsSeparatorTkn: $2,
|
||||||
|
StringTkn: $3,
|
||||||
// save comments
|
Value: $3.Value,
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
})
|
||||||
yylex.(*Parser).setFreeFloating(namePart, token.Start, $3.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -355,43 +355,49 @@ top_statement:
|
|||||||
}
|
}
|
||||||
| T_NAMESPACE namespace_name ';'
|
| T_NAMESPACE namespace_name ';'
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $2}
|
$$ = &ast.StmtNamespace{
|
||||||
$$ = &ast.StmtNamespace{ast.Node{}, name, nil}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $3),
|
||||||
// save position
|
},
|
||||||
name.GetNode().Position = position.NewNodeListPosition($2)
|
NsTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
Name: &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save comments
|
Position: position.NewNodeListPosition($2),
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
},
|
||||||
yylex.(*Parser).setFreeFloating(name, token.End, $3.SkippedTokens)
|
Parts: $2,
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
},
|
||||||
|
SemiColonTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $2}
|
$$ = &ast.StmtNamespace{
|
||||||
$$ = &ast.StmtNamespace{ast.Node{}, name, $4}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $5),
|
||||||
// save position
|
},
|
||||||
name.GetNode().Position = position.NewNodeListPosition($2)
|
NsTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $5)
|
Name: &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save comments
|
Position: position.NewNodeListPosition($2),
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
},
|
||||||
yylex.(*Parser).setFreeFloating(name, token.End, $3.SkippedTokens)
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $5.SkippedTokens)
|
},
|
||||||
|
OpenCurlyBracket: $3,
|
||||||
|
Stmts: $4,
|
||||||
|
CloseCurlyBracket: $5,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE '{' top_statement_list '}'
|
| T_NAMESPACE '{' top_statement_list '}'
|
||||||
{
|
{
|
||||||
$$ = &ast.StmtNamespace{ast.Node{}, nil, $3}
|
$$ = &ast.StmtNamespace{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $4),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $4)
|
},
|
||||||
|
NsTkn: $1,
|
||||||
// save comments
|
OpenCurlyBracket: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Stmts: $3,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
CloseCurlyBracket: $4,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $4.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| T_USE use_declarations ';'
|
| T_USE use_declarations ';'
|
||||||
{
|
{
|
||||||
@ -1595,10 +1601,12 @@ interface_list:
|
|||||||
}
|
}
|
||||||
| interface_list ',' fully_qualified_class_name
|
| interface_list ',' fully_qualified_class_name
|
||||||
{
|
{
|
||||||
|
switch n := lastNode($1).(type) {
|
||||||
|
case *ast.NameName: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameFullyQualified: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameRelative: n.ListSeparatorTkn = $2
|
||||||
|
}
|
||||||
$$ = append($1, $3)
|
$$ = append($1, $3)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2413,10 +2421,12 @@ trait_list:
|
|||||||
}
|
}
|
||||||
| trait_list ',' fully_qualified_class_name
|
| trait_list ',' fully_qualified_class_name
|
||||||
{
|
{
|
||||||
|
switch n := lastNode($1).(type) {
|
||||||
|
case *ast.NameName: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameFullyQualified: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameRelative: n.ListSeparatorTkn = $2
|
||||||
|
}
|
||||||
$$ = append($1, $3)
|
$$ = append($1, $3)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -3992,37 +4002,45 @@ lexical_var_list:
|
|||||||
function_call:
|
function_call:
|
||||||
namespace_name function_call_parameter_list
|
namespace_name function_call_parameter_list
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $1}
|
name := &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewNodeListPosition($1),
|
||||||
|
},
|
||||||
|
Parts: $1,
|
||||||
|
}
|
||||||
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $2.(*ast.ArgumentList)}
|
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $2.(*ast.ArgumentList)}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewNodeListPosition($1)
|
|
||||||
$$.GetNode().Position = position.NewNodesPosition(name, $2)
|
$$.GetNode().Position = position.NewNodesPosition(name, $2)
|
||||||
}
|
}
|
||||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name function_call_parameter_list
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name function_call_parameter_list
|
||||||
{
|
{
|
||||||
funcName := &ast.NameRelative{ast.Node{}, $3}
|
name := &ast.NameRelative{
|
||||||
$$ = &ast.ExprFunctionCall{ast.Node{}, funcName, $4.(*ast.ArgumentList)}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodeListPosition($1, $3),
|
||||||
|
},
|
||||||
|
NsTkn: $1,
|
||||||
|
NsSeparatorTkn: $2,
|
||||||
|
Parts: $3,
|
||||||
|
}
|
||||||
|
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $4.(*ast.ArgumentList)}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
funcName.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
$$.GetNode().Position = position.NewNodesPosition(name, $4)
|
||||||
$$.GetNode().Position = position.NewNodesPosition(funcName, $4)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating(funcName, token.Namespace, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_NS_SEPARATOR namespace_name function_call_parameter_list
|
| T_NS_SEPARATOR namespace_name function_call_parameter_list
|
||||||
{
|
{
|
||||||
funcName := &ast.NameFullyQualified{ast.Node{}, $2}
|
name := &ast.NameFullyQualified{
|
||||||
$$ = &ast.ExprFunctionCall{ast.Node{}, funcName, $3.(*ast.ArgumentList)}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodeListPosition($1, $2),
|
||||||
|
},
|
||||||
|
NsSeparatorTkn: $1,
|
||||||
|
Parts: $2,
|
||||||
|
}
|
||||||
|
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $3.(*ast.ArgumentList)}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
funcName.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
$$.GetNode().Position = position.NewNodesPosition(name, $3)
|
||||||
$$.GetNode().Position = position.NewNodesPosition(funcName, $3)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
|
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
|
||||||
{
|
{
|
||||||
@ -4093,62 +4111,66 @@ class_name:
|
|||||||
}
|
}
|
||||||
| namespace_name
|
| namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameName{ast.Node{}, $1}
|
$$ = &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeListPosition($1),
|
||||||
$$.GetNode().Position = position.NewNodeListPosition($1)
|
},
|
||||||
|
Parts: $1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameRelative{ast.Node{}, $3}
|
$$ = &ast.NameRelative{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodeListPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
},
|
||||||
|
NsTkn: $1,
|
||||||
// save comments
|
NsSeparatorTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Parts: $3,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| T_NS_SEPARATOR namespace_name
|
| T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameFullyQualified{ast.Node{}, $2}
|
$$ = &ast.NameFullyQualified{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodeListPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
},
|
||||||
|
NsSeparatorTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
fully_qualified_class_name:
|
fully_qualified_class_name:
|
||||||
namespace_name
|
namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameName{ast.Node{}, $1}
|
$$ = &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeListPosition($1),
|
||||||
$$.GetNode().Position = position.NewNodeListPosition($1)
|
},
|
||||||
|
Parts: $1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameRelative{ast.Node{}, $3}
|
$$ = &ast.NameRelative{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodeListPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
},
|
||||||
|
NsTkn: $1,
|
||||||
// save comments
|
NsSeparatorTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Parts: $3,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| T_NS_SEPARATOR namespace_name
|
| T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameFullyQualified{ast.Node{}, $2}
|
$$ = &ast.NameFullyQualified{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodeListPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
},
|
||||||
|
NsSeparatorTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -4444,37 +4466,45 @@ static_scalar_value:
|
|||||||
}
|
}
|
||||||
| namespace_name
|
| namespace_name
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $1}
|
name := &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewNodeListPosition($1),
|
||||||
|
},
|
||||||
|
Parts: $1,
|
||||||
|
}
|
||||||
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewNodeListPosition($1)
|
|
||||||
$$.GetNode().Position = position.NewNodePosition(name)
|
$$.GetNode().Position = position.NewNodePosition(name)
|
||||||
}
|
}
|
||||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
name := &ast.NameRelative{ast.Node{}, $3}
|
name := &ast.NameRelative{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodeListPosition($1, $3),
|
||||||
|
},
|
||||||
|
NsTkn: $1,
|
||||||
|
NsSeparatorTkn: $2,
|
||||||
|
Parts: $3,
|
||||||
|
}
|
||||||
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_NS_SEPARATOR namespace_name
|
| T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
name := &ast.NameFullyQualified{ast.Node{}, $2}
|
name := &ast.NameFullyQualified{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodeListPosition($1, $2),
|
||||||
|
},
|
||||||
|
NsSeparatorTkn: $1,
|
||||||
|
Parts: $2,
|
||||||
|
}
|
||||||
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_ARRAY '(' static_array_pair_list ')'
|
| T_ARRAY '(' static_array_pair_list ')'
|
||||||
{
|
{
|
||||||
@ -4888,37 +4918,45 @@ general_constant:
|
|||||||
}
|
}
|
||||||
| namespace_name
|
| namespace_name
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $1}
|
name := &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewNodeListPosition($1),
|
||||||
|
},
|
||||||
|
Parts: $1,
|
||||||
|
}
|
||||||
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewNodeListPosition($1)
|
|
||||||
$$.GetNode().Position = position.NewNodePosition(name)
|
$$.GetNode().Position = position.NewNodePosition(name)
|
||||||
}
|
}
|
||||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
name := &ast.NameRelative{ast.Node{}, $3}
|
name := &ast.NameRelative{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodeListPosition($1, $3),
|
||||||
|
},
|
||||||
|
NsTkn: $1,
|
||||||
|
NsSeparatorTkn: $2,
|
||||||
|
Parts: $3,
|
||||||
|
}
|
||||||
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
|
||||||
$$.GetNode().Position = position.NewNodePosition(name)
|
$$.GetNode().Position = position.NewNodePosition(name)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating(name, token.Namespace, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_NS_SEPARATOR namespace_name
|
| T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
name := &ast.NameFullyQualified{ast.Node{}, $2}
|
name := &ast.NameFullyQualified{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodeListPosition($1, $2),
|
||||||
|
},
|
||||||
|
NsSeparatorTkn: $1,
|
||||||
|
Parts: $2,
|
||||||
|
}
|
||||||
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
$$ = &ast.ExprConstFetch{ast.Node{}, name}
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
name.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
|
||||||
$$.GetNode().Position = position.NewNodePosition(name)
|
$$.GetNode().Position = position.NewNodePosition(name)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -6290,7 +6290,7 @@ func TestPhp5(t *testing.T) {
|
|||||||
EndPos: 2376,
|
EndPos: 2376,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 109,
|
StartLine: 109,
|
||||||
@ -6323,7 +6323,7 @@ func TestPhp5(t *testing.T) {
|
|||||||
EndPos: 2397,
|
EndPos: 2397,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 110,
|
StartLine: 110,
|
||||||
@ -6349,7 +6349,7 @@ func TestPhp5(t *testing.T) {
|
|||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 110,
|
StartLine: 110,
|
||||||
EndLine: 110,
|
EndLine: 110,
|
||||||
StartPos: 2391,
|
StartPos: 2390,
|
||||||
EndPos: 2394,
|
EndPos: 2394,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -9214,7 +9214,7 @@ func TestStmtNamespace(t *testing.T) {
|
|||||||
EndPos: 17,
|
EndPos: 17,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 1,
|
StartLine: 1,
|
||||||
@ -9272,7 +9272,7 @@ func TestStmtNamespace_Stmts(t *testing.T) {
|
|||||||
EndPos: 19,
|
EndPos: 19,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 1,
|
StartLine: 1,
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -350,57 +350,59 @@ top_statement_list:
|
|||||||
namespace_name:
|
namespace_name:
|
||||||
T_STRING
|
T_STRING
|
||||||
{
|
{
|
||||||
namePart := &ast.NameNamePart{ast.Node{}, $1.Value}
|
$$ = []ast.Vertex{
|
||||||
$$ = []ast.Vertex{namePart}
|
&ast.NameNamePart{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenPosition($1),
|
||||||
namePart.GetNode().Position = position.NewTokenPosition($1)
|
},
|
||||||
|
StringTkn: $1,
|
||||||
// save comments
|
Value: $1.Value,
|
||||||
yylex.(*Parser).setFreeFloating(namePart, token.Start, $1.SkippedTokens)
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| namespace_name T_NS_SEPARATOR T_STRING
|
| namespace_name T_NS_SEPARATOR T_STRING
|
||||||
{
|
{
|
||||||
namePart := &ast.NameNamePart{ast.Node{}, $3.Value}
|
$$ = append($1, &ast.NameNamePart{
|
||||||
$$ = append($1, namePart)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($2, $3),
|
||||||
// save position
|
},
|
||||||
namePart.GetNode().Position = position.NewTokenPosition($3)
|
NsSeparatorTkn: $2,
|
||||||
|
StringTkn: $3,
|
||||||
// save comments
|
Value: $3.Value,
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
})
|
||||||
yylex.(*Parser).setFreeFloating(namePart, token.Start, $3.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
name:
|
name:
|
||||||
namespace_name
|
namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameName{ast.Node{}, $1}
|
$$ = &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeListPosition($1),
|
||||||
$$.GetNode().Position = position.NewNodeListPosition($1)
|
},
|
||||||
|
Parts: $1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
| T_NAMESPACE T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameRelative{ast.Node{}, $3}
|
$$ = &ast.NameRelative{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodeListPosition($1, $3),
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
},
|
||||||
|
NsTkn: $1,
|
||||||
// save comments
|
NsSeparatorTkn: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Parts: $3,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| T_NS_SEPARATOR namespace_name
|
| T_NS_SEPARATOR namespace_name
|
||||||
{
|
{
|
||||||
$$ = &ast.NameFullyQualified{ast.Node{}, $2}
|
$$ = &ast.NameFullyQualified{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokenNodeListPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
},
|
||||||
|
NsSeparatorTkn: $1,
|
||||||
// save comments
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -443,45 +445,49 @@ top_statement:
|
|||||||
}
|
}
|
||||||
| T_NAMESPACE namespace_name ';'
|
| T_NAMESPACE namespace_name ';'
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $2}
|
$$ = &ast.StmtNamespace{
|
||||||
$$ = &ast.StmtNamespace{ast.Node{}, name, nil}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $3),
|
||||||
// save position
|
},
|
||||||
name.GetNode().Position = position.NewNodeListPosition($2)
|
NsTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
Name: &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save comments
|
Position: position.NewNodeListPosition($2),
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
},
|
||||||
yylex.(*Parser).MoveFreeFloating($2[0], name)
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating(name, token.End, $3.SkippedTokens)
|
},
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
SemiColonTkn: $3,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
||||||
{
|
{
|
||||||
name := &ast.NameName{ast.Node{}, $2}
|
$$ = &ast.StmtNamespace{
|
||||||
$$ = &ast.StmtNamespace{ast.Node{}, name, $4}
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokensPosition($1, $5),
|
||||||
// save position
|
},
|
||||||
name.GetNode().Position = position.NewNodeListPosition($2)
|
NsTkn: $1,
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $5)
|
Name: &ast.NameName{
|
||||||
|
Node: ast.Node{
|
||||||
// save comments
|
Position: position.NewNodeListPosition($2),
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
},
|
||||||
yylex.(*Parser).MoveFreeFloating($2[0], name)
|
Parts: $2,
|
||||||
yylex.(*Parser).setFreeFloating(name, token.End, $3.SkippedTokens)
|
},
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $5.SkippedTokens)
|
OpenCurlyBracket: $3,
|
||||||
|
Stmts: $4,
|
||||||
|
CloseCurlyBracket: $5,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| T_NAMESPACE '{' top_statement_list '}'
|
| T_NAMESPACE '{' top_statement_list '}'
|
||||||
{
|
{
|
||||||
$$ = &ast.StmtNamespace{ast.Node{}, nil, $3}
|
$$ = &ast.StmtNamespace{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewTokensPosition($1, $4),
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $4)
|
},
|
||||||
|
NsTkn: $1,
|
||||||
// save comments
|
OpenCurlyBracket: $2,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
Stmts: $3,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
CloseCurlyBracket: $4,
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $4.SkippedTokens)
|
}
|
||||||
}
|
}
|
||||||
| T_USE mixed_group_use_declaration ';'
|
| T_USE mixed_group_use_declaration ';'
|
||||||
{
|
{
|
||||||
@ -1222,10 +1228,12 @@ catch_name_list:
|
|||||||
}
|
}
|
||||||
| catch_name_list '|' name
|
| catch_name_list '|' name
|
||||||
{
|
{
|
||||||
|
switch n := lastNode($1).(type) {
|
||||||
|
case *ast.NameName: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameFullyQualified: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameRelative: n.ListSeparatorTkn = $2
|
||||||
|
}
|
||||||
$$ = append($1, $3)
|
$$ = append($1, $3)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2251,10 +2259,12 @@ name_list:
|
|||||||
}
|
}
|
||||||
| name_list ',' name
|
| name_list ',' name
|
||||||
{
|
{
|
||||||
|
switch n := lastNode($1).(type) {
|
||||||
|
case *ast.NameName: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameFullyQualified: n.ListSeparatorTkn = $2
|
||||||
|
case *ast.NameRelative: n.ListSeparatorTkn = $2
|
||||||
|
}
|
||||||
$$ = append($1, $3)
|
$$ = append($1, $3)
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -6962,7 +6962,7 @@ func TestPhp7(t *testing.T) {
|
|||||||
EndPos: 2525,
|
EndPos: 2525,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 115,
|
StartLine: 115,
|
||||||
@ -6995,7 +6995,7 @@ func TestPhp7(t *testing.T) {
|
|||||||
EndPos: 2542,
|
EndPos: 2542,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 116,
|
StartLine: 116,
|
||||||
@ -17695,7 +17695,7 @@ func TestPhp7(t *testing.T) {
|
|||||||
Position: &position.Position{
|
Position: &position.Position{
|
||||||
StartLine: 318,
|
StartLine: 318,
|
||||||
EndLine: 318,
|
EndLine: 318,
|
||||||
StartPos: 5212,
|
StartPos: 5211,
|
||||||
EndPos: 5215,
|
EndPos: 5215,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -603,8 +603,12 @@ func (n *StmtLabel) Accept(v NodeVisitor) {
|
|||||||
// StmtNamespace node
|
// StmtNamespace node
|
||||||
type StmtNamespace struct {
|
type StmtNamespace struct {
|
||||||
Node
|
Node
|
||||||
NamespaceName Vertex
|
NsTkn *token.Token
|
||||||
Stmts []Vertex
|
Name Vertex
|
||||||
|
OpenCurlyBracket *token.Token
|
||||||
|
Stmts []Vertex
|
||||||
|
CloseCurlyBracket *token.Token
|
||||||
|
SemiColonTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtNamespace) Accept(v NodeVisitor) {
|
func (n *StmtNamespace) Accept(v NodeVisitor) {
|
||||||
@ -1840,7 +1844,8 @@ func (n *ExprBinarySpaceship) Accept(v NodeVisitor) {
|
|||||||
|
|
||||||
type NameName struct {
|
type NameName struct {
|
||||||
Node
|
Node
|
||||||
Parts []Vertex
|
Parts []Vertex
|
||||||
|
ListSeparatorTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameName) Accept(v NodeVisitor) {
|
func (n *NameName) Accept(v NodeVisitor) {
|
||||||
@ -1849,7 +1854,9 @@ func (n *NameName) Accept(v NodeVisitor) {
|
|||||||
|
|
||||||
type NameFullyQualified struct {
|
type NameFullyQualified struct {
|
||||||
Node
|
Node
|
||||||
Parts []Vertex
|
NsSeparatorTkn *token.Token
|
||||||
|
Parts []Vertex
|
||||||
|
ListSeparatorTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameFullyQualified) Accept(v NodeVisitor) {
|
func (n *NameFullyQualified) Accept(v NodeVisitor) {
|
||||||
@ -1858,7 +1865,10 @@ func (n *NameFullyQualified) Accept(v NodeVisitor) {
|
|||||||
|
|
||||||
type NameRelative struct {
|
type NameRelative struct {
|
||||||
Node
|
Node
|
||||||
Parts []Vertex
|
NsTkn *token.Token
|
||||||
|
NsSeparatorTkn *token.Token
|
||||||
|
Parts []Vertex
|
||||||
|
ListSeparatorTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameRelative) Accept(v NodeVisitor) {
|
func (n *NameRelative) Accept(v NodeVisitor) {
|
||||||
@ -1867,7 +1877,9 @@ func (n *NameRelative) Accept(v NodeVisitor) {
|
|||||||
|
|
||||||
type NameNamePart struct {
|
type NameNamePart struct {
|
||||||
Node
|
Node
|
||||||
Value []byte
|
NsSeparatorTkn *token.Token
|
||||||
|
StringTkn *token.Token
|
||||||
|
Value []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NameNamePart) Accept(v NodeVisitor) {
|
func (n *NameNamePart) Accept(v NodeVisitor) {
|
||||||
|
@ -845,10 +845,10 @@ func (t *DFS) Traverse(n ast.Vertex) {
|
|||||||
if !t.visitor.EnterNode(nn) {
|
if !t.visitor.EnterNode(nn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if nn.NamespaceName != nil {
|
if nn.Name != nil {
|
||||||
t.visitor.Enter("NamespaceName", true)
|
t.visitor.Enter("Name", true)
|
||||||
t.Traverse(nn.NamespaceName)
|
t.Traverse(nn.Name)
|
||||||
t.visitor.Leave("NamespaceName", true)
|
t.visitor.Leave("Name", true)
|
||||||
}
|
}
|
||||||
if nn.Stmts != nil {
|
if nn.Stmts != nil {
|
||||||
t.visitor.Enter("Stmts", false)
|
t.visitor.Enter("Stmts", false)
|
||||||
|
@ -33,3 +33,30 @@ func (v *FilterTokens) StmtUseDeclaration(n *ast.StmtUseDeclaration) {
|
|||||||
n.AsTkn = nil
|
n.AsTkn = nil
|
||||||
n.CommaTkn = 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) {
|
func (nsr *NamespaceResolver) StmtNamespace(n *ast.StmtNamespace) {
|
||||||
if n.NamespaceName == nil {
|
if n.Name == nil {
|
||||||
nsr.Namespace = NewNamespace("")
|
nsr.Namespace = NewNamespace("")
|
||||||
} else {
|
} else {
|
||||||
NSParts := n.NamespaceName.(*ast.NameName).Parts
|
NSParts := n.Name.(*ast.NameName).Parts
|
||||||
nsr.Namespace = NewNamespace(concatNameParts(NSParts))
|
nsr.Namespace = NewNamespace(concatNameParts(NSParts))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,7 +605,7 @@ func TestResolveConstantsName(t *testing.T) {
|
|||||||
stxTree := &ast.StmtStmtList{
|
stxTree := &ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: nameAB,
|
Name: nameAB,
|
||||||
},
|
},
|
||||||
&ast.StmtConstList{
|
&ast.StmtConstList{
|
||||||
Consts: []ast.Vertex{
|
Consts: []ast.Vertex{
|
||||||
@ -649,7 +649,7 @@ func TestResolveNamespaces(t *testing.T) {
|
|||||||
stxTree := &ast.StmtStmtList{
|
stxTree := &ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: namespaceAB,
|
Name: namespaceAB,
|
||||||
},
|
},
|
||||||
&ast.StmtConstList{
|
&ast.StmtConstList{
|
||||||
Consts: []ast.Vertex{
|
Consts: []ast.Vertex{
|
||||||
@ -666,7 +666,7 @@ func TestResolveNamespaces(t *testing.T) {
|
|||||||
Stmts: []ast.Vertex{},
|
Stmts: []ast.Vertex{},
|
||||||
},
|
},
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: namespaceCD,
|
Name: namespaceCD,
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtUse{
|
&ast.StmtUse{
|
||||||
UseDeclarations: []ast.Vertex{
|
UseDeclarations: []ast.Vertex{
|
||||||
@ -749,7 +749,7 @@ func TestDoNotResolveReservedConstants(t *testing.T) {
|
|||||||
stxTree := &ast.StmtStmtList{
|
stxTree := &ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: namespaceName,
|
Name: namespaceName,
|
||||||
},
|
},
|
||||||
&ast.StmtExpression{
|
&ast.StmtExpression{
|
||||||
Expr: &ast.ExprConstFetch{
|
Expr: &ast.ExprConstFetch{
|
||||||
@ -877,7 +877,7 @@ func TestDoNotResolveReservedNames(t *testing.T) {
|
|||||||
stxTree := &ast.StmtStmtList{
|
stxTree := &ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Parts: []ast.Vertex{
|
Parts: []ast.Vertex{
|
||||||
&ast.NameNamePart{Value: []byte("Foo")},
|
&ast.NameNamePart{Value: []byte("Foo")},
|
||||||
},
|
},
|
||||||
@ -955,7 +955,7 @@ func TestDoNotResolveReservedSpecialNames(t *testing.T) {
|
|||||||
stxTree := &ast.StmtStmtList{
|
stxTree := &ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Parts: []ast.Vertex{
|
Parts: []ast.Vertex{
|
||||||
&ast.NameNamePart{Value: []byte("Foo")},
|
&ast.NameNamePart{Value: []byte("Foo")},
|
||||||
},
|
},
|
||||||
@ -1007,7 +1007,7 @@ func TestResolvePropertyTypeName(t *testing.T) {
|
|||||||
stmts := &ast.StmtStmtList{
|
stmts := &ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Parts: []ast.Vertex{
|
Parts: []ast.Vertex{
|
||||||
&ast.NameNamePart{Value: []byte("Foo")},
|
&ast.NameNamePart{Value: []byte("Foo")},
|
||||||
},
|
},
|
||||||
|
@ -1931,9 +1931,9 @@ func (p *PrettyPrinter) printStmtNamespace(n ast.Vertex) {
|
|||||||
|
|
||||||
io.WriteString(p.w, "namespace")
|
io.WriteString(p.w, "namespace")
|
||||||
|
|
||||||
if nn.NamespaceName != nil {
|
if nn.Name != nil {
|
||||||
io.WriteString(p.w, " ")
|
io.WriteString(p.w, " ")
|
||||||
p.Print(nn.NamespaceName)
|
p.Print(nn.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nn.Stmts != nil {
|
if nn.Stmts != nil {
|
||||||
|
@ -22,7 +22,7 @@ abstract class Bar extends Baz
|
|||||||
rootNode := &ast.Root{
|
rootNode := &ast.Root{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Parts: []ast.Vertex{
|
Parts: []ast.Vertex{
|
||||||
&ast.NameNamePart{Value: []byte("Foo")},
|
&ast.NameNamePart{Value: []byte("Foo")},
|
||||||
},
|
},
|
||||||
@ -3454,7 +3454,7 @@ func TestPrintNamespace(t *testing.T) {
|
|||||||
|
|
||||||
p := printer.NewPrettyPrinter(o, " ")
|
p := printer.NewPrettyPrinter(o, " ")
|
||||||
p.Print(&ast.StmtNamespace{
|
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;`
|
expected := `namespace Foo;`
|
||||||
@ -3472,7 +3472,7 @@ func TestPrintNamespaceWithStmts(t *testing.T) {
|
|||||||
p.Print(&ast.StmtStmtList{
|
p.Print(&ast.StmtStmtList{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&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{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtExpression{Expr: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("a")}}},
|
&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) {
|
func (p *Printer) printNodes(nn []ast.Vertex) {
|
||||||
for _, n := range nn {
|
for _, n := range nn {
|
||||||
p.Print(n)
|
p.Print(n)
|
||||||
@ -558,50 +568,36 @@ func (p *Printer) printNodeArgument(n ast.Vertex) {
|
|||||||
|
|
||||||
// name
|
// name
|
||||||
|
|
||||||
func (p *Printer) printNameNamePart(n ast.Vertex) {
|
func (p *Printer) printNameNamePart(n *ast.NameNamePart) {
|
||||||
nn := n.(*ast.NameNamePart)
|
p.printToken(n.NsSeparatorTkn, "")
|
||||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
p.printToken(n.StringTkn, string(n.Value))
|
||||||
p.bufStart = ""
|
|
||||||
|
|
||||||
io.WriteString(p.w, string(nn.Value))
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.End)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printNameName(n ast.Vertex) {
|
func (p *Printer) printNameName(n *ast.NameName) {
|
||||||
nn := n.(*ast.NameName)
|
p.printFreeFloating(n, token.Start)
|
||||||
p.printFreeFloating(nn, 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) {
|
func (p *Printer) printNameFullyQualified(n *ast.NameFullyQualified) {
|
||||||
nn := n.(*ast.NameFullyQualified)
|
p.printFreeFloating(n, token.Start)
|
||||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
p.printToken(n.NsSeparatorTkn, "\\")
|
||||||
p.bufStart = ""
|
|
||||||
|
|
||||||
io.WriteString(p.w, "\\")
|
p.joinPrintRefactored("\\", n.Parts)
|
||||||
p.joinPrint("\\", nn.Parts)
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.End)
|
p.printToken(n.ListSeparatorTkn, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printNameRelative(n ast.Vertex) {
|
func (p *Printer) printNameRelative(n *ast.NameRelative) {
|
||||||
nn := n.(*ast.NameRelative)
|
p.printFreeFloating(n, token.Start)
|
||||||
p.printFreeFloatingOrDefault(nn, token.Start, p.bufStart)
|
p.printToken(n.NsTkn, "namespace")
|
||||||
p.bufStart = ""
|
p.printToken(n.NsSeparatorTkn, "\\")
|
||||||
|
|
||||||
io.WriteString(p.w, "namespace")
|
p.joinPrintRefactored("\\", n.Parts)
|
||||||
p.printFreeFloating(nn, token.Namespace)
|
|
||||||
|
|
||||||
for _, part := range nn.Parts {
|
p.printToken(n.ListSeparatorTkn, "")
|
||||||
io.WriteString(p.w, "\\")
|
|
||||||
p.Print(part)
|
|
||||||
}
|
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.End)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// scalar
|
// scalar
|
||||||
@ -2299,7 +2295,9 @@ func (p *Printer) printStmtCatch(n ast.Vertex) {
|
|||||||
io.WriteString(p.w, "catch")
|
io.WriteString(p.w, "catch")
|
||||||
p.printFreeFloating(nn, token.Catch)
|
p.printFreeFloating(nn, token.Catch)
|
||||||
io.WriteString(p.w, "(")
|
io.WriteString(p.w, "(")
|
||||||
p.joinPrint("|", nn.Types)
|
|
||||||
|
p.joinPrintRefactored("|", nn.Types)
|
||||||
|
|
||||||
p.Print(nn.Var)
|
p.Print(nn.Var)
|
||||||
p.printFreeFloating(nn, token.Var)
|
p.printFreeFloating(nn, token.Var)
|
||||||
io.WriteString(p.w, ")")
|
io.WriteString(p.w, ")")
|
||||||
@ -2409,10 +2407,9 @@ func (p *Printer) printStmtClass(n ast.Vertex) {
|
|||||||
io.WriteString(p.w, " ")
|
io.WriteString(p.w, " ")
|
||||||
}
|
}
|
||||||
io.WriteString(p.w, "implements")
|
io.WriteString(p.w, "implements")
|
||||||
if nn.Implements.InterfaceNames[0].GetNode().Tokens.IsEmpty() {
|
p.bufStart = " "
|
||||||
io.WriteString(p.w, " ")
|
p.joinPrintRefactored(",", nn.Implements.InterfaceNames)
|
||||||
}
|
|
||||||
p.joinPrint(",", nn.Implements.InterfaceNames)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.Name)
|
p.printFreeFloating(nn, token.Name)
|
||||||
@ -2896,10 +2893,8 @@ func (p *Printer) printStmtInterface(n ast.Vertex) {
|
|||||||
io.WriteString(p.w, " ")
|
io.WriteString(p.w, " ")
|
||||||
}
|
}
|
||||||
io.WriteString(p.w, "extends")
|
io.WriteString(p.w, "extends")
|
||||||
if nn.Extends.InterfaceNames[0].GetNode().Tokens.IsEmpty() {
|
p.bufStart = " "
|
||||||
io.WriteString(p.w, " ")
|
p.joinPrintRefactored(",", nn.Extends.InterfaceNames)
|
||||||
}
|
|
||||||
p.joinPrint(",", nn.Extends.InterfaceNames)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printFreeFloating(nn, token.Name)
|
p.printFreeFloating(nn, token.Name)
|
||||||
@ -2923,32 +2918,28 @@ func (p *Printer) printStmtLabel(n ast.Vertex) {
|
|||||||
p.printFreeFloating(nn, token.End)
|
p.printFreeFloating(nn, token.End)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtNamespace(n ast.Vertex) {
|
func (p *Printer) printStmtNamespace(n *ast.StmtNamespace) {
|
||||||
nn := n.(*ast.StmtNamespace)
|
p.printToken(n.NsTkn, "namespace")
|
||||||
p.printFreeFloating(nn, token.Start)
|
|
||||||
io.WriteString(p.w, "namespace")
|
|
||||||
|
|
||||||
if nn.NamespaceName != nil {
|
if n.Name != nil {
|
||||||
if nn.NamespaceName.GetNode().Tokens.IsEmpty() {
|
p.bufStart = " "
|
||||||
io.WriteString(p.w, " ")
|
p.Print(n.Name)
|
||||||
}
|
|
||||||
p.Print(nn.NamespaceName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if nn.Stmts != nil {
|
if n.Stmts != nil {
|
||||||
p.printFreeFloating(nn, token.Namespace)
|
p.printToken(n.OpenCurlyBracket, "{")
|
||||||
io.WriteString(p.w, "{")
|
p.printNodes(n.Stmts)
|
||||||
p.printNodes(nn.Stmts)
|
p.printToken(n.CloseCurlyBracket, "}")
|
||||||
p.printFreeFloating(nn, token.Stmts)
|
return
|
||||||
io.WriteString(p.w, "}")
|
|
||||||
} else {
|
|
||||||
p.printFreeFloating(nn, token.SemiColon)
|
|
||||||
if nn.GetNode().Tokens.IsEmpty() {
|
|
||||||
io.WriteString(p.w, ";")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
func (p *Printer) printStmtNop(n ast.Vertex) {
|
||||||
@ -3202,10 +3193,8 @@ func (p *Printer) printStmtTraitUse(n ast.Vertex) {
|
|||||||
p.printFreeFloating(nn, token.Start)
|
p.printFreeFloating(nn, token.Start)
|
||||||
|
|
||||||
io.WriteString(p.w, "use")
|
io.WriteString(p.w, "use")
|
||||||
if nn.Traits[0].GetNode().Tokens.IsEmpty() {
|
p.bufStart = " "
|
||||||
io.WriteString(p.w, " ")
|
p.joinPrintRefactored(",", nn.Traits)
|
||||||
}
|
|
||||||
p.joinPrint(",", nn.Traits)
|
|
||||||
|
|
||||||
p.Print(nn.TraitAdaptationList)
|
p.Print(nn.TraitAdaptationList)
|
||||||
|
|
||||||
@ -3276,11 +3265,13 @@ func (p *Printer) printStmtUnset(n ast.Vertex) {
|
|||||||
func (p *Printer) printStmtUse(n *ast.StmtUse) {
|
func (p *Printer) printStmtUse(n *ast.StmtUse) {
|
||||||
p.printToken(n.UseTkn, "use")
|
p.printToken(n.UseTkn, "use")
|
||||||
|
|
||||||
p.bufStart = " "
|
if n.Type != nil {
|
||||||
p.Print(n.Type)
|
p.bufStart = " "
|
||||||
|
p.Print(n.Type)
|
||||||
|
}
|
||||||
|
|
||||||
p.bufStart = " "
|
p.bufStart = " "
|
||||||
p.joinPrint(",", n.UseDeclarations)
|
p.joinPrintRefactored(",", n.UseDeclarations)
|
||||||
|
|
||||||
p.printToken(n.SemiColonTkn, ";")
|
p.printToken(n.SemiColonTkn, ";")
|
||||||
}
|
}
|
||||||
@ -3298,16 +3289,7 @@ func (p *Printer) printStmtGroupUse(n *ast.StmtGroupUse) {
|
|||||||
p.printToken(n.NsSeparatorTkn, "\\")
|
p.printToken(n.NsSeparatorTkn, "\\")
|
||||||
p.printToken(n.OpenCurlyBracketTkn, "{")
|
p.printToken(n.OpenCurlyBracketTkn, "{")
|
||||||
|
|
||||||
for k, v := range n.UseDeclarations {
|
p.joinPrintRefactored(",", 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.printToken(n.CloseCurlyBracketTkn, "}")
|
p.printToken(n.CloseCurlyBracketTkn, "}")
|
||||||
p.printToken(n.SemiColonTkn, ";")
|
p.printToken(n.SemiColonTkn, ";")
|
||||||
@ -3325,6 +3307,7 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
|
|||||||
p.Print(n.Use)
|
p.Print(n.Use)
|
||||||
|
|
||||||
if n.Alias == nil {
|
if n.Alias == nil {
|
||||||
|
p.printToken(n.CommaTkn, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3333,6 +3316,8 @@ func (p *Printer) printStmtUseDeclaration(n *ast.StmtUseDeclaration) {
|
|||||||
|
|
||||||
p.bufStart = " "
|
p.bufStart = " "
|
||||||
p.Print(n.Alias)
|
p.Print(n.Alias)
|
||||||
|
|
||||||
|
p.printToken(n.CommaTkn, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtWhile(n ast.Vertex) {
|
func (p *Printer) printStmtWhile(n ast.Vertex) {
|
||||||
|
@ -45,8 +45,8 @@ func TestParseAndPrintPhp5Root(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5Identifier(t *testing.T) {
|
func TestParseAndPrintPhp5Identifier(t *testing.T) {
|
||||||
|
// TODO: remove ; after <?php
|
||||||
src := `<?
|
src := `<? ;
|
||||||
/* Foo */
|
/* Foo */
|
||||||
Foo ( ) ;
|
Foo ( ) ;
|
||||||
`
|
`
|
||||||
@ -73,8 +73,8 @@ func TestParseAndPrintPhp5Parameter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5Argument(t *testing.T) {
|
func TestParseAndPrintPhp5Argument(t *testing.T) {
|
||||||
|
// TODO: remove ; after <?php
|
||||||
src := `<?php
|
src := `<?php ;
|
||||||
foo ( $a , $b
|
foo ( $a , $b
|
||||||
, $c
|
, $c
|
||||||
) ; `
|
) ; `
|
||||||
@ -89,7 +89,8 @@ func TestParseAndPrintPhp5Argument(t *testing.T) {
|
|||||||
// test name
|
// test name
|
||||||
|
|
||||||
func TestParseAndPrintPhp5Names(t *testing.T) {
|
func TestParseAndPrintPhp5Names(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
foo ( ) ;
|
foo ( ) ;
|
||||||
\ foo ( ) ;
|
\ foo ( ) ;
|
||||||
namespace \ foo ( ) ;
|
namespace \ foo ( ) ;
|
||||||
@ -168,7 +169,8 @@ func TestParseAndPrintPhp5String(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5Heredoc(t *testing.T) {
|
func TestParseAndPrintPhp5Heredoc(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
foo(<<<EAP
|
foo(<<<EAP
|
||||||
test
|
test
|
||||||
EAP
|
EAP
|
||||||
@ -289,7 +291,8 @@ func TestParseAndPrintPhp5Cast(t *testing.T) {
|
|||||||
// test expr
|
// test expr
|
||||||
|
|
||||||
func TestParseAndPrintPhp5ArrayDimFetch(t *testing.T) {
|
func TestParseAndPrintPhp5ArrayDimFetch(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
FOO [ ] ;
|
FOO [ ] ;
|
||||||
FOO [ 1 ] ;
|
FOO [ 1 ] ;
|
||||||
$a [ ] ;
|
$a [ ] ;
|
||||||
@ -415,7 +418,8 @@ func TestParseAndPrintPhp5Closure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5ConstFetch(t *testing.T) {
|
func TestParseAndPrintPhp5ConstFetch(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
null ;
|
null ;
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -481,7 +485,8 @@ func TestParseAndPrintPhp5Exit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5FunctionCall(t *testing.T) {
|
func TestParseAndPrintPhp5FunctionCall(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
foo ( ) ;
|
foo ( ) ;
|
||||||
$var ( $a , ... $b , $c ) ;
|
$var ( $a , ... $b , $c ) ;
|
||||||
`
|
`
|
||||||
@ -551,7 +556,8 @@ func TestParseAndPrintPhp5MethodCall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5New(t *testing.T) {
|
func TestParseAndPrintPhp5New(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
|
|
||||||
new Foo ;
|
new Foo ;
|
||||||
|
|
||||||
@ -664,7 +670,8 @@ func TestParseAndPrintPhp5ShortArray(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
Foo :: bar ( $a , $b ) ;`
|
Foo :: bar ( $a , $b ) ;`
|
||||||
|
|
||||||
actual := printPhp5(parsePhp5(src))
|
actual := printPhp5(parsePhp5(src))
|
||||||
@ -675,7 +682,8 @@ func TestParseAndPrintPhp5StaticCall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5StaticPropertyFetch(t *testing.T) {
|
func TestParseAndPrintPhp5StaticPropertyFetch(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
Foo :: $bar ;`
|
Foo :: $bar ;`
|
||||||
|
|
||||||
actual := printPhp5(parsePhp5(src))
|
actual := printPhp5(parsePhp5(src))
|
||||||
@ -1117,7 +1125,8 @@ func TestParseAndPrintPhp5GotoLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintPhp5Namespace(t *testing.T) {
|
func TestParseAndPrintPhp5Namespace(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
namespace Foo \ Bar ;
|
namespace Foo \ Bar ;
|
||||||
namespace Baz {
|
namespace Baz {
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ExamplePrinter() {
|
func ExamplePrinter() {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
|
|
||||||
namespace Foo;
|
namespace Foo;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ abstract class Bar extends Baz
|
|||||||
|
|
||||||
// change namespace
|
// 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")})
|
*parts = append(*parts, &ast.NameNamePart{Value: []byte("Quuz")})
|
||||||
|
|
||||||
// print
|
// print
|
||||||
@ -46,7 +47,7 @@ abstract class Bar extends Baz
|
|||||||
p.Print(rootNode)
|
p.Print(rootNode)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
//<?php
|
//<?php ;
|
||||||
//
|
//
|
||||||
// namespace Foo\Quuz;
|
// namespace Foo\Quuz;
|
||||||
//
|
//
|
||||||
@ -94,8 +95,8 @@ func TestParseAndPrintRoot(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintIdentifier(t *testing.T) {
|
func TestParseAndPrintIdentifier(t *testing.T) {
|
||||||
|
// TODO: remove ; after <?php
|
||||||
src := `<?
|
src := `<? ;
|
||||||
/* Foo */
|
/* Foo */
|
||||||
Foo ( ) ;
|
Foo ( ) ;
|
||||||
`
|
`
|
||||||
@ -151,8 +152,8 @@ func TestParseAndPrintNullable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintArgument(t *testing.T) {
|
func TestParseAndPrintArgument(t *testing.T) {
|
||||||
|
// TODO: remove ; after <?php
|
||||||
src := `<?php
|
src := `<?php ;
|
||||||
foo ( $a , $b
|
foo ( $a , $b
|
||||||
, ... $c ,
|
, ... $c ,
|
||||||
) ; `
|
) ; `
|
||||||
@ -167,7 +168,8 @@ func TestParseAndPrintArgument(t *testing.T) {
|
|||||||
// test name
|
// test name
|
||||||
|
|
||||||
func TestParseAndPrintNames(t *testing.T) {
|
func TestParseAndPrintNames(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
foo ( ) ;
|
foo ( ) ;
|
||||||
\ foo ( ) ;
|
\ foo ( ) ;
|
||||||
namespace \ foo ( ) ;
|
namespace \ foo ( ) ;
|
||||||
@ -246,7 +248,8 @@ func TestParseAndPrintString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintHeredoc(t *testing.T) {
|
func TestParseAndPrintHeredoc(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
foo(<<<EAP
|
foo(<<<EAP
|
||||||
test
|
test
|
||||||
EAP
|
EAP
|
||||||
@ -370,7 +373,8 @@ func TestParseAndPrintCast(t *testing.T) {
|
|||||||
// test expr
|
// test expr
|
||||||
|
|
||||||
func TestParseAndPrintArrayDimFetch(t *testing.T) {
|
func TestParseAndPrintArrayDimFetch(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
FOO [ ] ;
|
FOO [ ] ;
|
||||||
FOO [ 1 ] ;
|
FOO [ 1 ] ;
|
||||||
$a [ ] ;
|
$a [ ] ;
|
||||||
@ -509,7 +513,8 @@ func TestParseAndPrintArrowFunction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintConstFetch(t *testing.T) {
|
func TestParseAndPrintConstFetch(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
null ;
|
null ;
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -575,7 +580,8 @@ func TestParseAndPrintExit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintFunctionCall(t *testing.T) {
|
func TestParseAndPrintFunctionCall(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
foo ( ) ;
|
foo ( ) ;
|
||||||
$var ( $a , ... $b , $c ) ;
|
$var ( $a , ... $b , $c ) ;
|
||||||
`
|
`
|
||||||
@ -776,7 +782,8 @@ func TestParseAndPrintShortList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintStaticCall(t *testing.T) {
|
func TestParseAndPrintStaticCall(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
Foo :: bar ( $a , $b ) ;`
|
Foo :: bar ( $a , $b ) ;`
|
||||||
|
|
||||||
actual := print(parse(src))
|
actual := print(parse(src))
|
||||||
@ -787,7 +794,8 @@ func TestParseAndPrintStaticCall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintStaticPropertyFetch(t *testing.T) {
|
func TestParseAndPrintStaticPropertyFetch(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
Foo :: $bar ;`
|
Foo :: $bar ;`
|
||||||
|
|
||||||
actual := print(parse(src))
|
actual := print(parse(src))
|
||||||
@ -1250,7 +1258,8 @@ func TestParseAndPrintGotoLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndPrintNamespace(t *testing.T) {
|
func TestParseAndPrintNamespace(t *testing.T) {
|
||||||
src := `<?php
|
// TODO: remove ; after <?php
|
||||||
|
src := `<?php ;
|
||||||
namespace Foo \ Bar ;
|
namespace Foo \ Bar ;
|
||||||
namespace Baz {
|
namespace Baz {
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ func TestPrinterPrintFile(t *testing.T) {
|
|||||||
p.Print(&ast.Root{
|
p.Print(&ast.Root{
|
||||||
Stmts: []ast.Vertex{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtNamespace{
|
&ast.StmtNamespace{
|
||||||
NamespaceName: &ast.NameName{
|
Name: &ast.NameName{
|
||||||
Parts: []ast.Vertex{
|
Parts: []ast.Vertex{
|
||||||
&ast.NameNamePart{Value: []byte("Foo")},
|
&ast.NameNamePart{Value: []byte("Foo")},
|
||||||
},
|
},
|
||||||
@ -3862,7 +3862,7 @@ func TestPrinterPrintNamespace(t *testing.T) {
|
|||||||
|
|
||||||
p := printer.NewPrinter(o)
|
p := printer.NewPrinter(o)
|
||||||
p.Print(&ast.StmtNamespace{
|
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;`
|
expected := `namespace Foo;`
|
||||||
@ -3878,7 +3878,7 @@ func TestPrinterPrintNamespaceWithStmts(t *testing.T) {
|
|||||||
|
|
||||||
p := printer.NewPrinter(o)
|
p := printer.NewPrinter(o)
|
||||||
p.Print(&ast.StmtNamespace{
|
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{
|
Stmts: []ast.Vertex{
|
||||||
&ast.StmtExpression{Expr: &ast.ExprVariable{
|
&ast.StmtExpression{Expr: &ast.ExprVariable{
|
||||||
VarName: &ast.Identifier{Value: []byte("$a")},
|
VarName: &ast.Identifier{Value: []byte("$a")},
|
||||||
|
Loading…
Reference in New Issue
Block a user