[refactoring] update ast structure of "Constant" nodes
This commit is contained in:
@@ -4318,7 +4318,7 @@ func TestStmtClassConstList(t *testing.T) {
|
||||
EndPos: 34,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -4350,7 +4350,7 @@ func TestStmtClassConstList(t *testing.T) {
|
||||
EndPos: 43,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -4442,7 +4442,7 @@ func TestStmtClassConstList_WithoutModifiers(t *testing.T) {
|
||||
EndPos: 27,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -4474,7 +4474,7 @@ func TestStmtClassConstList_WithoutModifiers(t *testing.T) {
|
||||
EndPos: 36,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -5721,7 +5721,7 @@ func TestStmtConstList(t *testing.T) {
|
||||
EndPos: 16,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -5753,7 +5753,7 @@ func TestStmtConstList(t *testing.T) {
|
||||
EndPos: 25,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -6048,7 +6048,7 @@ func TestStmtDeclare(t *testing.T) {
|
||||
EndPos: 18,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -6127,7 +6127,7 @@ func TestStmtDeclare_Stmts(t *testing.T) {
|
||||
EndPos: 18,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -6159,7 +6159,7 @@ func TestStmtDeclare_Stmts(t *testing.T) {
|
||||
EndPos: 34,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
@@ -6239,7 +6239,7 @@ func TestStmtDeclare_Alt(t *testing.T) {
|
||||
EndPos: 18,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
|
||||
1082
internal/php7/php7.go
generated
1082
internal/php7/php7.go
generated
File diff suppressed because it is too large
Load Diff
@@ -536,15 +536,14 @@ top_statement:
|
||||
}
|
||||
| T_CONST const_list ';'
|
||||
{
|
||||
$$ = &ast.StmtConstList{ast.Node{}, $2}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $3.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
|
||||
$$ = &ast.StmtConstList{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
ConstTkn: $1,
|
||||
Consts: $2,
|
||||
SemiColonTkn: $3,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@@ -782,10 +781,9 @@ use_declaration:
|
||||
const_list:
|
||||
const_list ',' const_decl
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
lastNode($1).(*ast.StmtConstant).CommaTkn = $2
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
$$ = append($1, $3)
|
||||
}
|
||||
| const_decl
|
||||
{
|
||||
@@ -2198,20 +2196,15 @@ class_statement:
|
||||
}
|
||||
| method_modifiers T_CONST class_const_list ';'
|
||||
{
|
||||
$$ = &ast.StmtClassConstList{ast.Node{}, $1, $3}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewOptionalListTokensPosition($1, $2, $4)
|
||||
|
||||
// save comments
|
||||
if len($1) > 0 {
|
||||
yylex.(*Parser).MoveFreeFloating($1[0], $$)
|
||||
yylex.(*Parser).setFreeFloating($$, token.ModifierList, $2.SkippedTokens)
|
||||
} else {
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $2.SkippedTokens)
|
||||
$$ = &ast.StmtClassConstList{
|
||||
Node: ast.Node{
|
||||
Position: position.NewOptionalListTokensPosition($1, $2, $4),
|
||||
},
|
||||
Modifiers: $1,
|
||||
ConstTkn: $2,
|
||||
Consts: $3,
|
||||
SemiColonTkn: $4,
|
||||
}
|
||||
yylex.(*Parser).setFreeFloating($$, token.ConstList, $4.SkippedTokens)
|
||||
yylex.(*Parser).setToken($$, token.SemiColon, $4.SkippedTokens)
|
||||
}
|
||||
| T_USE name_list trait_adaptations
|
||||
{
|
||||
@@ -2616,10 +2609,9 @@ property:
|
||||
class_const_list:
|
||||
class_const_list ',' class_const_decl
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
lastNode($1).(*ast.StmtConstant).CommaTkn = $2
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
||||
$$ = append($1, $3)
|
||||
}
|
||||
| class_const_decl
|
||||
{
|
||||
@@ -2630,32 +2622,42 @@ class_const_list:
|
||||
class_const_decl:
|
||||
identifier '=' expr backup_doc_comment
|
||||
{
|
||||
name := &ast.Identifier{ast.Node{}, $1.Value}
|
||||
$$ = &ast.StmtConstant{ast.Node{}, name, $3}
|
||||
$$ = &ast.StmtConstant{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodePosition($1, $3),
|
||||
},
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
Value: $1.Value,
|
||||
},
|
||||
EqualTkn: $2,
|
||||
Expr: $3,
|
||||
}
|
||||
|
||||
// save position
|
||||
name.GetNode().Position = position.NewTokenPosition($1)
|
||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$.(*ast.StmtConstant).Name, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
const_decl:
|
||||
T_STRING '=' expr backup_doc_comment
|
||||
{
|
||||
name := &ast.Identifier{ast.Node{}, $1.Value}
|
||||
$$ = &ast.StmtConstant{ast.Node{}, name, $3}
|
||||
$$ = &ast.StmtConstant{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodePosition($1, $3),
|
||||
},
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
Value: $1.Value,
|
||||
},
|
||||
EqualTkn: $2,
|
||||
Expr: $3,
|
||||
}
|
||||
|
||||
// save position
|
||||
name.GetNode().Position = position.NewTokenPosition($1)
|
||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$, token.Name, $2.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating($$.(*ast.StmtConstant).Name, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -3919,7 +3919,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1322,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 70,
|
||||
@@ -3951,7 +3951,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1331,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 70,
|
||||
@@ -4018,7 +4018,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1359,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 71,
|
||||
@@ -4050,7 +4050,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1368,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 71,
|
||||
@@ -4732,7 +4732,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1693,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 81,
|
||||
@@ -4764,7 +4764,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1702,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 81,
|
||||
@@ -4959,7 +4959,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1796,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 85,
|
||||
@@ -5013,7 +5013,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1814,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 86,
|
||||
@@ -5069,7 +5069,7 @@ func TestPhp7(t *testing.T) {
|
||||
EndPos: 1834,
|
||||
},
|
||||
},
|
||||
ConstantName: &ast.Identifier{
|
||||
Name: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: &position.Position{
|
||||
StartLine: 87,
|
||||
|
||||
Reference in New Issue
Block a user