[refactoring] update ast structure of "Eval", "Exit", "FunctionCall", "Include" and "IncludeOnce" nodes

This commit is contained in:
Vadym Slizov
2020-12-01 11:58:09 +02:00
parent 2d240e9475
commit 9b122de8bf
9 changed files with 1333 additions and 1335 deletions

1284
internal/php5/php5.go generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,6 @@
package php5
import (
"bytes"
"strconv"
"github.com/z7zmey/php-parser/internal/position"
@@ -3872,21 +3871,20 @@ expr_without_variable:
}
| T_EXIT exit_expr
{
$$ = &ast.ExprExit{ast.Node{}, false, $2}
if (bytes.EqualFold($1.Value, []byte("die"))) {
$$.(*ast.ExprExit).Die = true
exit := &ast.ExprExit{
DieTkn: $1,
}
// save position
if $2 == nil {
$$.GetNode().Position = position.NewTokenPosition($1)
exit.Node.Position = position.NewTokenPosition($1)
} else {
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
exit.Node.Position = position.NewTokenNodePosition($1, $2)
exit.OpenParenthesisTkn = $2.(*ast.ParserBrackets).OpenBracketTkn
exit.Expr = $2.(*ast.ParserBrackets).Child
exit.CloseParenthesisTkn = $2.(*ast.ParserBrackets).CloseBracketTkn
}
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = exit
}
| '@' expr
{
@@ -4228,45 +4226,57 @@ lexical_var_list:
function_call:
namespace_name function_call_parameter_list
{
name := &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
$$ = &ast.ExprFunctionCall{
Node: ast.Node{
Position: position.NewNodeListNodePosition($1, $2),
},
Parts: $1,
Function: &ast.NameName{
Node: ast.Node{
Position: position.NewNodeListPosition($1),
},
Parts: $1,
},
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
}
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $2.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition(name, $2)
}
| T_NAMESPACE T_NS_SEPARATOR namespace_name function_call_parameter_list
{
name := &ast.NameRelative{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3),
$$ = &ast.ExprFunctionCall{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $4),
},
NsTkn: $1,
NsSeparatorTkn: $2,
Parts: $3,
Function: &ast.NameRelative{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $3),
},
NsTkn: $1,
NsSeparatorTkn: $2,
Parts: $3,
},
OpenParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $4.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $4.(*ast.ArgumentList).OpenParenthesisTkn,
}
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $4.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition(name, $4)
}
| T_NS_SEPARATOR namespace_name function_call_parameter_list
{
name := &ast.NameFullyQualified{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2),
$$ = &ast.ExprFunctionCall{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $3),
},
NsSeparatorTkn: $1,
Parts: $2,
Function: &ast.NameFullyQualified{
Node: ast.Node{
Position: position.NewTokenNodeListPosition($1, $2),
},
NsSeparatorTkn: $1,
Parts: $2,
},
OpenParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $3.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $3.(*ast.ArgumentList).OpenParenthesisTkn,
}
$$ = &ast.ExprFunctionCall{ast.Node{}, name, $3.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition(name, $3)
}
| class_name T_PAAMAYIM_NEKUDOTAYIM variable_name function_call_parameter_list
{
@@ -4314,13 +4324,15 @@ function_call:
}
| variable_without_objects function_call_parameter_list
{
$$ = &ast.ExprFunctionCall{ast.Node{}, $1, $2.(*ast.ArgumentList)}
// save position
$$.GetNode().Position = position.NewNodesPosition($1, $2)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
$$ = &ast.ExprFunctionCall{
Node: ast.Node{
Position: position.NewNodesPosition($1, $2),
},
Function: $1,
OpenParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
Arguments: $2.(*ast.ArgumentList).Arguments,
CloseParenthesisTkn: $2.(*ast.ArgumentList).OpenParenthesisTkn,
}
}
;
@@ -6355,43 +6367,35 @@ internal_functions_in_yacc:
}
| T_INCLUDE expr
{
$$ = &ast.ExprInclude{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprInclude{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
IncludeTkn: $1,
Expr: $2,
}
}
| T_INCLUDE_ONCE expr
{
$$ = &ast.ExprIncludeOnce{ast.Node{}, $2}
// save position
$$.GetNode().Position = position.NewTokenNodePosition($1, $2)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ExprIncludeOnce{
Node: ast.Node{
Position: position.NewTokenNodePosition($1, $2),
},
IncludeTkn: $1,
Expr: $2,
}
}
| T_EVAL '(' expr ')'
{
exprBrackets := &ast.ParserBrackets{
$$ = &ast.ExprEval{
Node: ast.Node{
Position: position.NewTokensPosition($2, $4),
Position: position.NewTokensPosition($1, $4),
},
OpenBracketTkn: $2,
Child: $3,
CloseBracketTkn: $4,
EvalTkn: $1,
OpenParenthesisTkn: $2,
Expr: $3,
CloseParenthesisTkn: $4,
}
$$ = &ast.ExprEval{ast.Node{}, exprBrackets}
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $4)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.Start, $2.SkippedTokens)
yylex.(*Parser).setFreeFloatingTokens(exprBrackets, token.End, $4.SkippedTokens)
}
| T_REQUIRE expr
{