[refactoring] update ast structure of "ArrayDimFetch", "UnaryMinus", "ExprUnaryPlus" and "Variable" nodes
This commit is contained in:
1358
internal/php7/php7.go
generated
1358
internal/php7/php7.go
generated
File diff suppressed because it is too large
Load Diff
@@ -1122,19 +1122,21 @@ catch_list:
|
||||
}
|
||||
| catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($5),
|
||||
},
|
||||
IdentifierTkn: $5,
|
||||
Value: $5.Value,
|
||||
}
|
||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
||||
|
||||
catch := $4.(*ast.StmtCatch)
|
||||
catch.CatchTkn = $2
|
||||
catch.OpenParenthesisTkn = $3
|
||||
catch.Var = variable
|
||||
catch.Var = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($5),
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($5),
|
||||
},
|
||||
IdentifierTkn: $5,
|
||||
Value: $5.Value,
|
||||
},
|
||||
}
|
||||
catch.CloseParenthesisTkn = $6
|
||||
catch.OpenCurlyBracketTkn = $7
|
||||
catch.Stmts = $8
|
||||
@@ -1142,12 +1144,6 @@ catch_list:
|
||||
catch.GetNode().Position = position.NewTokensPosition($2, $9)
|
||||
|
||||
$$ = append($1, catch)
|
||||
|
||||
// save position
|
||||
variable.GetNode().Position = position.NewTokenPosition($5)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(variable, token.Start, $5.SkippedTokens)
|
||||
}
|
||||
;
|
||||
catch_name_list:
|
||||
@@ -1852,19 +1848,20 @@ non_empty_parameter_list:
|
||||
parameter:
|
||||
optional_type is_reference is_variadic T_VARIABLE
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
var variable ast.Vertex
|
||||
variable = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($4),
|
||||
},
|
||||
IdentifierTkn: $4,
|
||||
Value: $4.Value,
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($4),
|
||||
},
|
||||
IdentifierTkn: $4,
|
||||
Value: $4.Value,
|
||||
},
|
||||
}
|
||||
|
||||
var variable ast.Vertex
|
||||
variable = &ast.ExprVariable{ast.Node{}, identifier}
|
||||
variable.GetNode().Position = position.NewTokenPosition($4)
|
||||
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
|
||||
|
||||
if $3 != nil {
|
||||
variable = &ast.Variadic{
|
||||
Node: ast.Node{
|
||||
@@ -1904,20 +1901,20 @@ parameter:
|
||||
}
|
||||
| optional_type is_reference is_variadic T_VARIABLE '=' expr
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
var variable ast.Vertex
|
||||
variable = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($4),
|
||||
},
|
||||
IdentifierTkn: $4,
|
||||
Value: $4.Value,
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($4),
|
||||
},
|
||||
IdentifierTkn: $4,
|
||||
Value: $4.Value,
|
||||
},
|
||||
}
|
||||
|
||||
var variable ast.Vertex
|
||||
variable = &ast.ExprVariable{ast.Node{}, identifier}
|
||||
variable.GetNode().Position = position.NewTokenPosition($4)
|
||||
yylex.(*Parser).setFreeFloating(variable, token.Start, $4.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloating(variable, token.End, $5.SkippedTokens)
|
||||
|
||||
if $3 != nil {
|
||||
variable = &ast.Variadic{
|
||||
Node: ast.Node{
|
||||
@@ -2131,52 +2128,46 @@ static_var_list:
|
||||
static_var:
|
||||
T_VARIABLE
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
}
|
||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
||||
|
||||
$$ = &ast.StmtStaticVar{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
Var: variable,
|
||||
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// save position
|
||||
variable.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
| T_VARIABLE '=' expr
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
}
|
||||
variable := &ast.ExprVariable{ast.Node{}, identifier}
|
||||
$$ = &ast.StmtStaticVar{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodePosition($1, $3),
|
||||
},
|
||||
Var: variable,
|
||||
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,
|
||||
}
|
||||
|
||||
// save position
|
||||
variable.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating(variable, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
@@ -3254,23 +3245,23 @@ expr_without_variable:
|
||||
}
|
||||
| '+' expr %prec T_INC
|
||||
{
|
||||
$$ = &ast.ExprUnaryPlus{ast.Node{}, $2}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
$$ = &ast.ExprUnaryPlus{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodePosition($1, $2),
|
||||
},
|
||||
PlusTkn: $1,
|
||||
Expr: $2,
|
||||
}
|
||||
}
|
||||
| '-' expr %prec T_INC
|
||||
{
|
||||
$$ = &ast.ExprUnaryMinus{ast.Node{}, $2}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
$$ = &ast.ExprUnaryMinus{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodePosition($1, $2),
|
||||
},
|
||||
MinusTkn: $1,
|
||||
Expr: $2,
|
||||
}
|
||||
}
|
||||
| '!' expr
|
||||
{
|
||||
@@ -3744,20 +3735,18 @@ lexical_var_list:
|
||||
lexical_var:
|
||||
T_VARIABLE
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
$$ = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
}
|
||||
$$ = &ast.ExprVariable{ast.Node{}, identifier}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
| '&' T_VARIABLE
|
||||
{
|
||||
@@ -4334,42 +4323,45 @@ variable:
|
||||
simple_variable:
|
||||
T_VARIABLE
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
$$ = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
}
|
||||
$$ = &ast.ExprVariable{ast.Node{}, name}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
| '$' '{' expr '}'
|
||||
{
|
||||
$$ = &ast.ExprVariable{ast.Node{}, $3}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $4)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloatingTokens($3, token.Start, append($2.SkippedTokens, $3.GetNode().Tokens[token.Start]...))
|
||||
yylex.(*Parser).setFreeFloatingTokens($3, token.End, append($3.GetNode().Tokens[token.End], $4.SkippedTokens...))
|
||||
$$ = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $4),
|
||||
},
|
||||
DollarTkn: $1,
|
||||
VarName: &ast.ParserBrackets{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($2, $4),
|
||||
},
|
||||
OpenBracketTkn: $2,
|
||||
Child: $3,
|
||||
CloseBracketTkn: $4,
|
||||
},
|
||||
}
|
||||
}
|
||||
| '$' simple_variable
|
||||
{
|
||||
$$ = &ast.ExprVariable{ast.Node{}, $2}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
$$ = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenNodePosition($1, $2),
|
||||
},
|
||||
DollarTkn: $1,
|
||||
VarName: $2,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@@ -4696,20 +4688,18 @@ encaps_list:
|
||||
encaps_var:
|
||||
T_VARIABLE
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
$$ = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
}
|
||||
$$ = &ast.ExprVariable{ast.Node{}, name}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
| T_VARIABLE '[' encaps_var_offset ']'
|
||||
{
|
||||
@@ -4764,45 +4754,28 @@ encaps_var:
|
||||
}
|
||||
| T_DOLLAR_OPEN_CURLY_BRACES expr '}'
|
||||
{
|
||||
variable := &ast.ExprVariable{ast.Node{}, $2}
|
||||
|
||||
$$ = variable
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
|
||||
$$ = &ast.ParserBrackets{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
OpenBracketTkn: $1,
|
||||
Child: &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewNodePosition($2),
|
||||
},
|
||||
VarName: $2,
|
||||
},
|
||||
CloseBracketTkn: $3,
|
||||
}
|
||||
}
|
||||
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}'
|
||||
{
|
||||
name := &ast.Identifier{
|
||||
$$ = &ast.ParserBrackets{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
variable := &ast.ExprVariable{ast.Node{}, name}
|
||||
|
||||
$$ = variable
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $3)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
|
||||
}
|
||||
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
|
||||
{
|
||||
$$ = &ast.ExprArrayDimFetch{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $6),
|
||||
},
|
||||
OpenCurlyBracketTkn: $1,
|
||||
Var: &ast.ExprVariable{
|
||||
OpenBracketTkn: $1,
|
||||
Child: &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
@@ -4814,19 +4787,49 @@ encaps_var:
|
||||
Value: $2.Value,
|
||||
},
|
||||
},
|
||||
OpenBracketTkn: $3,
|
||||
Dim: $4,
|
||||
CloseBracketTkn: $5,
|
||||
CloseCurlyBracketTkn: $6,
|
||||
CloseBracketTkn: $3,
|
||||
}
|
||||
}
|
||||
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
|
||||
{
|
||||
$$ = &ast.ParserBrackets{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $6),
|
||||
},
|
||||
OpenBracketTkn: $1,
|
||||
Child: &ast.ExprArrayDimFetch{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($2, $5),
|
||||
},
|
||||
Var: &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
IdentifierTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
},
|
||||
OpenBracketTkn: $3,
|
||||
Dim: $4,
|
||||
CloseBracketTkn: $5,
|
||||
},
|
||||
CloseBracketTkn: $6,
|
||||
}
|
||||
}
|
||||
| T_CURLY_OPEN variable '}'
|
||||
{
|
||||
$$ = $2;
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setToken($$, token.Start, $1.SkippedTokens)
|
||||
yylex.(*Parser).setFreeFloatingTokens($$, token.End, $3.SkippedTokens)
|
||||
$$ = &ast.ParserBrackets{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokensPosition($1, $3),
|
||||
},
|
||||
OpenBracketTkn: $1,
|
||||
Child: $2,
|
||||
CloseBracketTkn: $3,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@@ -4868,14 +4871,19 @@ encaps_var_offset:
|
||||
isInt := err == nil
|
||||
|
||||
if isInt {
|
||||
lnumber := &ast.ScalarLnumber{
|
||||
$$ = &ast.ExprUnaryMinus{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
Position: position.NewTokensPosition($1, $2),
|
||||
},
|
||||
MinusTkn: $1,
|
||||
Expr: &ast.ScalarLnumber{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($2),
|
||||
},
|
||||
NumberTkn: $2,
|
||||
Value: $2.Value,
|
||||
},
|
||||
NumberTkn: $2,
|
||||
Value: $2.Value,
|
||||
}
|
||||
$$ = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
|
||||
$$.GetNode().Position = position.NewTokensPosition($1, $2)
|
||||
} else {
|
||||
$$ = &ast.ScalarString{
|
||||
@@ -4890,20 +4898,18 @@ encaps_var_offset:
|
||||
}
|
||||
| T_VARIABLE
|
||||
{
|
||||
identifier := &ast.Identifier{
|
||||
$$ = &ast.ExprVariable{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
VarName: &ast.Identifier{
|
||||
Node: ast.Node{
|
||||
Position: position.NewTokenPosition($1),
|
||||
},
|
||||
IdentifierTkn: $1,
|
||||
Value: $1.Value,
|
||||
},
|
||||
}
|
||||
$$ = &ast.ExprVariable{ast.Node{}, identifier}
|
||||
|
||||
// save position
|
||||
$$.GetNode().Position = position.NewTokenPosition($1)
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user