[refactoring] update ast structure of "name" nodes
This commit is contained in:
@@ -9214,7 +9214,7 @@ func TestStmtNamespace(t *testing.T) {
|
||||
EndPos: 17,
|
||||
},
|
||||
},
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -9272,7 +9272,7 @@ func TestStmtNamespace_Stmts(t *testing.T) {
|
||||
EndPos: 19,
|
||||
},
|
||||
},
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
|
||||
1010
internal/php7/php7.go
generated
1010
internal/php7/php7.go
generated
File diff suppressed because it is too large
Load Diff
@@ -350,57 +350,59 @@ top_statement_list:
|
||||
namespace_name:
|
||||
T_STRING
|
||||
{
|
||||
namePart := &ast.NameNamePart{ast.Node{}, $1.Value}
|
||||
$$ = []ast.Vertex{namePart}
|
||||
|
||||
// save position
|
||||
namePart.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(namePart, token.Start, $1.SkippedTokens)
|
||||
$$ = []ast.Vertex{
|
||||
&ast.NameNamePart{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
StringTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
}
|
||||
}
|
||||
| namespace_name T_NS_SEPARATOR T_STRING
|
||||
{
|
||||
namePart := &ast.NameNamePart{ast.Node{}, $3.Value}
|
||||
$$ = append($1, namePart)
|
||||
|
||||
// save position
|
||||
namePart.GetNode().Position = position.NewTokenPosition($3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating(namePart, token.Start, $3.SkippedTokens)
|
||||
$$ = append($1, &ast.NameNamePart{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($2, $3),
|
||||
},
|
||||
NsSeparatorTkn: $2,
|
||||
StringTkn: $3,
|
||||
Value: $3.Value,
|
||||
})
|
||||
}
|
||||
;
|
||||
|
||||
name:
|
||||
namespace_name
|
||||
{
|
||||
$$ = &ast.NameName{ast.Node{}, $1}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewNodeListPosition($1)
|
||||
$$ = &ast.NameName{
|
||||
Node: ast.Node{
|
||||
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}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
||||
$$ = &ast.NameRelative{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodeListPosition($1, $3),
|
||||
},
|
||||
NsTkn: $1,
|
||||
NsSeparatorTkn: $2,
|
||||
Parts: $3,
|
||||
}
|
||||
}
|
||||
| T_NS_SEPARATOR namespace_name
|
||||
| T_NS_SEPARATOR namespace_name
|
||||
{
|
||||
$$ = &ast.NameFullyQualified{ast.Node{}, $2}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenNodeListPosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
$$ = &ast.NameFullyQualified{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodeListPosition($1, $2),
|
||||
},
|
||||
NsSeparatorTkn: $1,
|
||||
Parts: $2,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@@ -443,45 +445,49 @@ top_statement:
|
||||
}
|
||||
| T_NAMESPACE namespace_name ';'
|
||||
{
|
||||
name := &ast.NameName{ast.Node{}, $2}
|
||||
$$ = &ast.StmtNamespace{ast.Node{}, name, nil}
|
||||
|
||||
// save position
|
||||
name.GetNode().Position = position.NewNodeListPosition($2)
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).MoveFreeFloating($2[0], name)
|
||||
yylex.(*Parser).setFreeFloating(name, token.End, $3.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
||||
$$ = &ast.StmtNamespace{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
NsTkn: $1,
|
||||
Name: &ast.NameName{
|
||||
Node: ast.Node{
|
||||
Position: position.NewNodeListPosition($2),
|
||||
},
|
||||
Parts: $2,
|
||||
},
|
||||
SemiColonTkn: $3,
|
||||
}
|
||||
}
|
||||
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
||||
{
|
||||
name := &ast.NameName{ast.Node{}, $2}
|
||||
$$ = &ast.StmtNamespace{ast.Node{}, name, $4}
|
||||
|
||||
// save position
|
||||
name.GetNode().Position = position.NewNodeListPosition($2)
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $5)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).MoveFreeFloating($2[0], name)
|
||||
yylex.(*Parser).setFreeFloating(name, token.End, $3.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $5.SkippedTokens)
|
||||
$$ = &ast.StmtNamespace{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $5),
|
||||
},
|
||||
NsTkn: $1,
|
||||
Name: &ast.NameName{
|
||||
Node: ast.Node{
|
||||
Position: position.NewNodeListPosition($2),
|
||||
},
|
||||
Parts: $2,
|
||||
},
|
||||
OpenCurlyBracket: $3,
|
||||
Stmts: $4,
|
||||
CloseCurlyBracket: $5,
|
||||
}
|
||||
}
|
||||
| T_NAMESPACE '{' top_statement_list '}'
|
||||
{
|
||||
$$ = &ast.StmtNamespace{ast.Node{}, nil, $3}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $4)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Namespace, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $4.SkippedTokens)
|
||||
$$ = &ast.StmtNamespace{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $4),
|
||||
},
|
||||
NsTkn: $1,
|
||||
OpenCurlyBracket: $2,
|
||||
Stmts: $3,
|
||||
CloseCurlyBracket: $4,
|
||||
}
|
||||
}
|
||||
| T_USE mixed_group_use_declaration ';'
|
||||
{
|
||||
@@ -1222,10 +1228,12 @@ catch_name_list:
|
||||
}
|
||||
| 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)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
@@ -2251,10 +2259,12 @@ name_list:
|
||||
}
|
||||
| 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)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -6962,7 +6962,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 2525,
|
||||
},
|
||||
},
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 115,
|
||||
@@ -6995,7 +6995,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 2542,
|
||||
},
|
||||
},
|
||||
NamespaceName: &ast.NameName{
|
||||
Name: &ast.NameName{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 116,
|
||||
@@ -17695,7 +17695,7 @@ func TestPhp7(t *testing.T) {
|
||||
Position: &position.Position{
|
||||
StartLine: 318,
|
||||
EndLine: 318,
|
||||
StartPos: 5212,
|
||||
StartPos: 5211,
|
||||
EndPos: 5215,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user