[refactoring] update ast structure of "StmtExpression", "StmtInterface" and "StmtProperty" nodes
This commit is contained in:
parent
2d6ae3a9a2
commit
5bd63d90ba
BIN
internal/php5/php5.go
generated
BIN
internal/php5/php5.go
generated
Binary file not shown.
@ -1033,15 +1033,13 @@ unticked_statement:
|
|||||||
}
|
}
|
||||||
| yield_expr ';'
|
| yield_expr ';'
|
||||||
{
|
{
|
||||||
$$ = &ast.StmtExpression{ast.Node{}, $1}
|
$$ = &ast.StmtExpression{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Expr: $1,
|
||||||
// save comments
|
SemiColonTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
|
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_GLOBAL global_var_list ';'
|
| T_GLOBAL global_var_list ';'
|
||||||
{
|
{
|
||||||
@ -1081,15 +1079,13 @@ unticked_statement:
|
|||||||
}
|
}
|
||||||
| expr ';'
|
| expr ';'
|
||||||
{
|
{
|
||||||
$$ = &ast.StmtExpression{ast.Node{}, $1}
|
$$ = &ast.StmtExpression{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Expr: $1,
|
||||||
// save comments
|
SemiColonTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
|
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_UNSET '(' unset_variables ')' ';'
|
| T_UNSET '(' unset_variables ')' ';'
|
||||||
{
|
{
|
||||||
@ -1439,22 +1435,23 @@ unticked_class_declaration_statement:
|
|||||||
}
|
}
|
||||||
| interface_entry T_STRING interface_extends_list '{' class_statement_list '}'
|
| interface_entry T_STRING interface_extends_list '{' class_statement_list '}'
|
||||||
{
|
{
|
||||||
name := &ast.Identifier{
|
$$ = &ast.StmtInterface{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokenPosition($2),
|
Position: position.NewTokensPosition($1, $6),
|
||||||
},
|
},
|
||||||
IdentifierTkn: $2,
|
InterfaceTkn: $1,
|
||||||
Value: $2.Value,
|
InterfaceName: &ast.Identifier{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($2),
|
||||||
|
},
|
||||||
|
IdentifierTkn: $2,
|
||||||
|
Value: $2.Value,
|
||||||
|
},
|
||||||
|
Extends: $3,
|
||||||
|
OpenCurlyBracketTkn: $4,
|
||||||
|
Stmts: $5,
|
||||||
|
CloseCurlyBracketTkn: $6,
|
||||||
}
|
}
|
||||||
$$ = &ast.StmtInterface{ast.Node{}, name, $3, $5}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $6)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Name, $4.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $6.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2851,87 +2848,92 @@ member_modifier:
|
|||||||
class_variable_declaration:
|
class_variable_declaration:
|
||||||
class_variable_declaration ',' T_VARIABLE
|
class_variable_declaration ',' T_VARIABLE
|
||||||
{
|
{
|
||||||
identifier := &ast.Identifier{
|
$$ = append($1, &ast.StmtProperty{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokenPosition($3),
|
Position: position.NewTokenPosition($3),
|
||||||
},
|
},
|
||||||
IdentifierTkn: $3,
|
Var: &ast.ExprVariable{
|
||||||
Value: $3.Value,
|
Node: ast.Node{
|
||||||
}
|
Position: position.NewTokenPosition($3),
|
||||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
},
|
||||||
property := &ast.StmtProperty{ast.Node{}, variable, nil}
|
VarName: &ast.Identifier{
|
||||||
$$ = append($1, property)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($3),
|
||||||
// save position
|
},
|
||||||
variable.GetNode().Position = position.NewTokenPosition($3)
|
IdentifierTkn: $3,
|
||||||
property.GetNode().Position = position.NewTokenPosition($3)
|
Value: $3.Value,
|
||||||
|
},
|
||||||
// save comments
|
},
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
})
|
||||||
yylex.(*Parser).setFreeFloating(property, token.Start, $3.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| class_variable_declaration ',' T_VARIABLE '=' static_scalar
|
| class_variable_declaration ',' T_VARIABLE '=' static_scalar
|
||||||
{
|
{
|
||||||
identifier := &ast.Identifier{
|
$$ = append($1, &ast.StmtProperty{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokenPosition($3),
|
Position: position.NewTokenNodePosition($3, $5),
|
||||||
},
|
},
|
||||||
IdentifierTkn: $3,
|
Var: &ast.ExprVariable{
|
||||||
Value: $3.Value,
|
Node: ast.Node{
|
||||||
}
|
Position: position.NewTokenPosition($3),
|
||||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
},
|
||||||
property := &ast.StmtProperty{ast.Node{}, variable, $5}
|
VarName: &ast.Identifier{
|
||||||
$$ = append($1, property)
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($3),
|
||||||
// save position
|
},
|
||||||
variable.GetNode().Position = position.NewTokenPosition($3)
|
IdentifierTkn: $3,
|
||||||
property.GetNode().Position = position.NewTokenNodePosition($3, $5)
|
Value: $3.Value,
|
||||||
|
},
|
||||||
// save comments
|
},
|
||||||
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
|
EqualTkn: $4,
|
||||||
yylex.(*Parser).setFreeFloating(property, token.Start, $3.SkippedTokens)
|
Expr: $5,
|
||||||
yylex.(*Parser).setFreeFloating(property, token.Var, $4.SkippedTokens)
|
})
|
||||||
}
|
}
|
||||||
| T_VARIABLE
|
| T_VARIABLE
|
||||||
{
|
{
|
||||||
identifier := &ast.Identifier{
|
$$ = []ast.Vertex{
|
||||||
Node: ast.Node{
|
&ast.StmtProperty{
|
||||||
Position: position.NewTokenPosition($1),
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
Var: &ast.ExprVariable{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
VarName: &ast.Identifier{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
IdentifierTkn: $1,
|
||||||
|
Value: $1.Value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Expr: nil,
|
||||||
},
|
},
|
||||||
IdentifierTkn: $1,
|
|
||||||
Value: $1.Value,
|
|
||||||
}
|
}
|
||||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
|
||||||
property := &ast.StmtProperty{ast.Node{}, variable, nil}
|
|
||||||
$$ = []ast.Vertex{property}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
variable.GetNode().Position = position.NewTokenPosition($1)
|
|
||||||
property.GetNode().Position = position.NewTokenPosition($1)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating(property, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_VARIABLE '=' static_scalar
|
| T_VARIABLE '=' static_scalar
|
||||||
{
|
{
|
||||||
identifier := &ast.Identifier{
|
$$ = []ast.Vertex{
|
||||||
Node: ast.Node{
|
&ast.StmtProperty{
|
||||||
Position: position.NewTokenPosition($1),
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenNodePosition($1, $3),
|
||||||
|
},
|
||||||
|
Var: &ast.ExprVariable{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
VarName: &ast.Identifier{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
IdentifierTkn: $1,
|
||||||
|
Value: $1.Value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
EqualTkn: $2,
|
||||||
|
Expr: $3,
|
||||||
},
|
},
|
||||||
IdentifierTkn: $1,
|
|
||||||
Value: $1.Value,
|
|
||||||
}
|
}
|
||||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
|
||||||
property := &ast.StmtProperty{ast.Node{}, variable, $3}
|
|
||||||
$$ = []ast.Vertex{property}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
variable.GetNode().Position = position.NewTokenPosition($1)
|
|
||||||
property.GetNode().Position = position.NewTokenNodePosition($1, $3)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating(property, token.Start, $2.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating(property, token.Var, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
BIN
internal/php7/php7.go
generated
BIN
internal/php7/php7.go
generated
Binary file not shown.
@ -989,15 +989,13 @@ statement:
|
|||||||
}
|
}
|
||||||
| expr ';'
|
| expr ';'
|
||||||
{
|
{
|
||||||
$$ = &ast.StmtExpression{ast.Node{}, $1}
|
$$ = &ast.StmtExpression{
|
||||||
|
Node: ast.Node{
|
||||||
// save position
|
Position: position.NewNodeTokenPosition($1, $2),
|
||||||
$$.GetNode().Position = position.NewNodeTokenPosition($1, $2)
|
},
|
||||||
|
Expr: $1,
|
||||||
// save comments
|
SemiColonTkn: $2,
|
||||||
yylex.(*Parser).MoveFreeFloating($1, $$)
|
}
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
|
|
||||||
yylex.(*Parser).setToken($$, token.SemiColon, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_UNSET '(' unset_variables possible_comma ')' ';'
|
| T_UNSET '(' unset_variables possible_comma ')' ';'
|
||||||
{
|
{
|
||||||
@ -1366,22 +1364,23 @@ trait_declaration_statement:
|
|||||||
interface_declaration_statement:
|
interface_declaration_statement:
|
||||||
T_INTERFACE T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
|
T_INTERFACE T_STRING interface_extends_list backup_doc_comment '{' class_statement_list '}'
|
||||||
{
|
{
|
||||||
name := &ast.Identifier{
|
$$ = &ast.StmtInterface{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokenPosition($2),
|
Position: position.NewTokensPosition($1, $7),
|
||||||
},
|
},
|
||||||
IdentifierTkn: $2,
|
InterfaceTkn: $1,
|
||||||
Value: $2.Value,
|
InterfaceName: &ast.Identifier{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($2),
|
||||||
|
},
|
||||||
|
IdentifierTkn: $2,
|
||||||
|
Value: $2.Value,
|
||||||
|
},
|
||||||
|
Extends: $3,
|
||||||
|
OpenCurlyBracketTkn: $5,
|
||||||
|
Stmts: $6,
|
||||||
|
CloseCurlyBracketTkn: $7,
|
||||||
}
|
}
|
||||||
$$ = &ast.StmtInterface{ast.Node{}, name, $3, $6}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
$$.GetNode().Position = position.NewTokensPosition($1, $7)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Name, $5.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Stmts, $7.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2609,42 +2608,46 @@ property_list:
|
|||||||
property:
|
property:
|
||||||
T_VARIABLE backup_doc_comment
|
T_VARIABLE backup_doc_comment
|
||||||
{
|
{
|
||||||
identifier := &ast.Identifier{
|
$$ = &ast.StmtProperty{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokenPosition($1),
|
Position: position.NewTokenPosition($1),
|
||||||
},
|
},
|
||||||
IdentifierTkn: $1,
|
Var: &ast.ExprVariable{
|
||||||
Value: $1.Value,
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
VarName: &ast.Identifier{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
IdentifierTkn: $1,
|
||||||
|
Value: $1.Value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Expr: nil,
|
||||||
}
|
}
|
||||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
|
||||||
$$ = &ast.StmtProperty{ast.Node{}, variable, nil}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
variable.GetNode().Position = position.NewTokenPosition($1)
|
|
||||||
$$.GetNode().Position = position.NewTokenPosition($1)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
| T_VARIABLE '=' expr backup_doc_comment
|
| T_VARIABLE '=' expr backup_doc_comment
|
||||||
{
|
{
|
||||||
identifier := &ast.Identifier{
|
$$ = &ast.StmtProperty{
|
||||||
Node: ast.Node{
|
Node: ast.Node{
|
||||||
Position: position.NewTokenPosition($1),
|
Position: position.NewTokenNodePosition($1, $3),
|
||||||
},
|
},
|
||||||
IdentifierTkn: $1,
|
Var: &ast.ExprVariable{
|
||||||
Value: $1.Value,
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
VarName: &ast.Identifier{
|
||||||
|
Node: ast.Node{
|
||||||
|
Position: position.NewTokenPosition($1),
|
||||||
|
},
|
||||||
|
IdentifierTkn: $1,
|
||||||
|
Value: $1.Value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
EqualTkn: $2,
|
||||||
|
Expr: $3,
|
||||||
}
|
}
|
||||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
|
||||||
$$ = &ast.StmtProperty{ast.Node{}, variable, $3}
|
|
||||||
|
|
||||||
// save position
|
|
||||||
variable.GetNode().Position = position.NewTokenPosition($1)
|
|
||||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $3)
|
|
||||||
|
|
||||||
// save comments
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
|
||||||
yylex.(*Parser).setFreeFloating($$, token.Var, $2.SkippedTokens)
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -438,7 +438,8 @@ func (n *StmtElseIf) Accept(v NodeVisitor) {
|
|||||||
// StmtExpression node
|
// StmtExpression node
|
||||||
type StmtExpression struct {
|
type StmtExpression struct {
|
||||||
Node
|
Node
|
||||||
Expr Vertex
|
Expr Vertex
|
||||||
|
SemiColonTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtExpression) Accept(v NodeVisitor) {
|
func (n *StmtExpression) Accept(v NodeVisitor) {
|
||||||
@ -594,9 +595,12 @@ func (n *StmtInlineHtml) Accept(v NodeVisitor) {
|
|||||||
// StmtInterface node
|
// StmtInterface node
|
||||||
type StmtInterface struct {
|
type StmtInterface struct {
|
||||||
Node
|
Node
|
||||||
InterfaceName Vertex
|
InterfaceTkn *token.Token
|
||||||
Extends Vertex
|
InterfaceName Vertex
|
||||||
Stmts []Vertex
|
Extends Vertex
|
||||||
|
OpenCurlyBracketTkn *token.Token
|
||||||
|
Stmts []Vertex
|
||||||
|
CloseCurlyBracketTkn *token.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtInterface) Accept(v NodeVisitor) {
|
func (n *StmtInterface) Accept(v NodeVisitor) {
|
||||||
@ -654,8 +658,9 @@ func (n *StmtNop) Accept(v NodeVisitor) {
|
|||||||
// StmtProperty node
|
// StmtProperty node
|
||||||
type StmtProperty struct {
|
type StmtProperty struct {
|
||||||
Node
|
Node
|
||||||
Var Vertex
|
Var Vertex
|
||||||
Expr Vertex
|
EqualTkn *token.Token
|
||||||
|
Expr Vertex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StmtProperty) Accept(v NodeVisitor) {
|
func (n *StmtProperty) Accept(v NodeVisitor) {
|
||||||
|
Loading…
Reference in New Issue
Block a user