[refactoring] update ast structure of "Echo" node

This commit is contained in:
Vadym Slizov
2020-09-10 23:11:08 +03:00
parent 3f12ada311
commit 7678303cb9
13 changed files with 1521 additions and 1614 deletions

1088
internal/php5/php5.go generated

File diff suppressed because it is too large Load Diff

View File

@@ -240,7 +240,7 @@ import (
%type <node> trait_use_statement function_call_parameter trait_adaptation_statement trait_precedence trait_alias
%type <node> trait_method_reference_fully_qualified trait_method_reference trait_modifiers member_modifier method
%type <node> static_scalar_value static_operation static_var_list global_var_list
%type <node> ctor_arguments function_call_parameter_list
%type <node> ctor_arguments function_call_parameter_list echo_expr_list
%type <node> trait_adaptations
%type <node> switch_case_list
%type <node> method_body
@@ -255,7 +255,7 @@ import (
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
%type <list> inner_statement_list encaps_list isset_variables non_empty_array_pair_list
%type <list> array_pair_list assignment_list lexical_var_list elseif_list new_elseif_list non_empty_for_expr
%type <list> for_expr case_list echo_expr_list unset_variables declare_list catch_statement additional_catches
%type <list> for_expr case_list unset_variables declare_list catch_statement additional_catches
%type <list> non_empty_additional_catches parameter_list non_empty_parameter_list class_statement_list
%type <list> class_statement_list variable_modifiers method_modifiers class_variable_declaration
%type <list> interface_list non_empty_function_call_parameter_list trait_list trait_adaptation_list non_empty_trait_adaptation_list
@@ -1054,16 +1054,11 @@ unticked_statement:
}
| T_ECHO echo_expr_list ';'
{
$$ = &ast.StmtEcho{ast.Node{}, $2}
$2.(*ast.StmtEcho).EchoTkn = $1
$2.(*ast.StmtEcho).SemiColonTkn = $3
$2.(*ast.StmtEcho).Node.Position = position.NewTokensPosition($1, $3)
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setToken($$, token.Echo, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
$$ = $2
}
| T_INLINE_HTML
{
@@ -2874,14 +2869,16 @@ class_constant_declaration:
echo_expr_list:
echo_expr_list ',' expr
{
$$ = append($1, $3)
$1.(*ast.StmtEcho).Exprs = append($1.(*ast.StmtEcho).Exprs, $3)
$1.(*ast.StmtEcho).SeparatorTkns = append($1.(*ast.StmtEcho).SeparatorTkns, $2)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = $1
}
| expr
{
$$ = []ast.Vertex{$1}
$$ = &ast.StmtEcho{
Exprs: []ast.Vertex{$1},
}
}
;
@@ -3335,7 +3332,6 @@ expr_without_variable:
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
}
| expr '+' expr

1152
internal/php7/php7.go generated

File diff suppressed because it is too large Load Diff

View File

@@ -249,7 +249,7 @@ import (
%type <node> exit_expr scalar lexical_var function_call member_name property_name
%type <node> variable_class_name dereferencable_scalar constant dereferencable
%type <node> callable_expr callable_variable static_member new_variable
%type <node> encaps_var encaps_var_offset
%type <node> encaps_var encaps_var_offset echo_expr_list
%type <node> if_stmt
%type <node> alt_if_stmt
%type <node> if_stmt_without_else
@@ -275,7 +275,7 @@ import (
%type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs
%type <list> const_list for_exprs non_empty_for_exprs
%type <list> unprefixed_use_declarations inline_use_declarations property_list
%type <list> case_list trait_adaptation_list unset_variables
%type <list> use_declarations lexical_var_list isset_variables non_empty_array_pair_list
@@ -954,7 +954,6 @@ statement:
{
$2.(*ast.StmtGlobal).GlobalTkn = $1
$2.(*ast.StmtGlobal).SemiColonTkn = $3
$2.(*ast.StmtGlobal).SeparatorTkns = append($2.(*ast.StmtGlobal).SeparatorTkns, nil)
$2.(*ast.StmtGlobal).Node.Position = position.NewTokensPosition($1, $3)
$$ = $2
@@ -963,23 +962,17 @@ statement:
{
$2.(*ast.StmtStatic).StaticTkn = $1
$2.(*ast.StmtStatic).SemiColonTkn = $3
$2.(*ast.StmtStatic).SeparatorTkns = append($2.(*ast.StmtStatic).SeparatorTkns, nil)
$2.(*ast.StmtStatic).Node.Position = position.NewTokensPosition($1, $3)
$$ = $2
}
| T_ECHO echo_expr_list ';'
{
$$ = &ast.StmtEcho{ast.Node{}, $2}
$2.(*ast.StmtEcho).EchoTkn = $1
$2.(*ast.StmtEcho).SemiColonTkn = $3
$2.(*ast.StmtEcho).Node.Position = position.NewTokensPosition($1, $3)
// save position
$$.GetNode().Position = position.NewTokensPosition($1, $3)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
yylex.(*Parser).setToken($$, token.Echo, $1.SkippedTokens)
yylex.(*Parser).setFreeFloating($$, token.Expr, $3.SkippedTokens)
yylex.(*Parser).setToken($$, token.SemiColon, $3.SkippedTokens)
$$ = $2
}
| T_INLINE_HTML
{
@@ -2629,14 +2622,16 @@ const_decl:
echo_expr_list:
echo_expr_list ',' echo_expr
{
$$ = append($1, $3)
$1.(*ast.StmtEcho).Exprs = append($1.(*ast.StmtEcho).Exprs, $3)
$1.(*ast.StmtEcho).SeparatorTkns = append($1.(*ast.StmtEcho).SeparatorTkns, $2)
// save comments
yylex.(*Parser).setFreeFloating(lastNode($1), token.End, $2.SkippedTokens)
$$ = $1
}
| echo_expr
{
$$ = []ast.Vertex{$1}
$$ = &ast.StmtEcho{
Exprs: []ast.Vertex{$1},
}
}
;
@@ -3061,7 +3056,6 @@ expr_without_variable:
$$.GetNode().Position = position.NewNodesPosition($1, $3)
// save comments
yylex.(*Parser).MoveFreeFloating($1, $$)
yylex.(*Parser).setFreeFloating($$, token.Expr, $2.SkippedTokens)
}
| expr '+' expr

View File

@@ -58,7 +58,7 @@ func (lex *Lexer) setTokenPosition(token *token.Token) {
}
func (lex *Lexer) addSkippedToken(t *token.Token, id token.ID, ps, pe int) {
if lex.sts == 0 {
if lex.sts == -1 {
lex.sts = lex.ts
}

View File

@@ -53,7 +53,7 @@ func (lex *Lexer) Lex() *token.Token {
tkn := lex.tokenPool.Get()
lex.sts = 0
lex.sts = -1
lex.ste = 0
lblStart := 0
@@ -24293,6 +24293,10 @@ func (lex *Lexer) Lex() *token.Token {
// line internal/scanner/scanner.rl:499
if lex.sts == -1 {
lex.sts = 0
}
tkn.Value = lex.data[lex.ts:lex.te]
tkn.ID = token.ID(tok)
tkn.Skipped = lex.data[lex.sts:lex.ste]

View File

@@ -26,7 +26,7 @@ func (lex *Lexer) Lex() *token.Token {
tkn := lex.tokenPool.Get()
lex.sts = 0
lex.sts = -1
lex.ste = 0
lblStart := 0
@@ -498,9 +498,13 @@ func (lex *Lexer) Lex() *token.Token {
write exec;
}%%
if lex.sts == -1 {
lex.sts = 0
}
tkn.Value = lex.data[lex.ts:lex.te]
tkn.ID = token.ID(tok)
tkn.SkippedString = lex.data[lex.sts:lex.ste]
tkn.Skipped = lex.data[lex.sts:lex.ste]
lex.addSkippedToken(tkn, tok, lex.ts, lex.te);
return tkn