remove altSintaxNode type

This commit is contained in:
z7zmey 2018-05-02 03:36:53 +03:00
parent a488f43496
commit e93874f644
4 changed files with 1575 additions and 1398 deletions

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,6 @@ import (
list []node.Node list []node.Node
foreachVariable foreachVariable foreachVariable foreachVariable
simpleIndirectReference simpleIndirectReference simpleIndirectReference simpleIndirectReference
altSyntaxNode altSyntaxNode
} }
%type <token> $unk %type <token> $unk
@ -245,6 +244,7 @@ import (
%type <node> trait_adaptations %type <node> trait_adaptations
%type <node> switch_case_list %type <node> switch_case_list
%type <node> method_body %type <node> method_body
%type <node> foreach_statement for_statement while_statement
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations %type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
%type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list %type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list
@ -262,7 +262,6 @@ import (
%type <simpleIndirectReference> simple_indirect_reference %type <simpleIndirectReference> simple_indirect_reference
%type <foreachVariable> foreach_variable foreach_optional_arg %type <foreachVariable> foreach_variable foreach_optional_arg
%type <boolWithToken> is_reference is_variadic %type <boolWithToken> is_reference is_variadic
%type <altSyntaxNode> while_statement for_statement foreach_statement
%% %%
@ -658,12 +657,16 @@ unticked_statement:
} }
| T_WHILE parenthesis_expr while_statement | T_WHILE parenthesis_expr while_statement
{ {
if ($3.isAlt) { switch n := $3.(type) {
$$ = stmt.NewAltWhile($2, $3.node) case *stmt.While :
} else { n.Cond = $2
$$ = stmt.NewWhile($2, $3.node) case *stmt.AltWhile :
n.Cond = $2
} }
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3.node))
$$ = $3
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $3))
yylex.(*Parser).comments.AddComments($$, $1.Comments()) yylex.(*Parser).comments.AddComments($$, $1.Comments())
} }
| T_DO statement T_WHILE parenthesis_expr ';' | T_DO statement T_WHILE parenthesis_expr ';'
@ -674,12 +677,20 @@ unticked_statement:
} }
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement | T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
{ {
if ($9.isAlt) { switch n := $9.(type) {
$$ = stmt.NewAltFor($3, $5, $7, $9.node) case *stmt.For :
} else { n.Init = $3
$$ = stmt.NewFor($3, $5, $7, $9.node) n.Cond = $5
n.Loop = $7
case *stmt.AltFor :
n.Init = $3
n.Cond = $5
n.Loop = $7
} }
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9.node))
$$ = $9
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9))
yylex.(*Parser).comments.AddComments($$, $1.Comments()) yylex.(*Parser).comments.AddComments($$, $1.Comments())
} }
| T_SWITCH parenthesis_expr switch_case_list | T_SWITCH parenthesis_expr switch_case_list
@ -785,37 +796,67 @@ unticked_statement:
| T_FOREACH '(' variable T_AS foreach_variable foreach_optional_arg ')' foreach_statement | T_FOREACH '(' variable T_AS foreach_variable foreach_optional_arg ')' foreach_statement
{ {
if $6.node == nil { if $6.node == nil {
if ($8.isAlt) { switch n := $8.(type) {
$$ = stmt.NewAltForeach($3, nil, $5.node, $8.node, $5.byRef) case *stmt.Foreach :
} else { n.Expr = $3
$$ = stmt.NewForeach($3, nil, $5.node, $8.node, $5.byRef) n.ByRef = $5.byRef
n.Variable = $5.node
case *stmt.AltForeach :
n.Expr = $3
n.ByRef = $5.byRef
n.Variable = $5.node
} }
} else { } else {
if ($8.isAlt) { switch n := $8.(type) {
$$ = stmt.NewAltForeach($3, $5.node, $6.node, $8.node, $6.byRef) case *stmt.Foreach :
} else { n.Expr = $3
$$ = stmt.NewForeach($3, $5.node, $6.node, $8.node, $6.byRef) n.Key = $5.node
n.ByRef = $6.byRef
n.Variable = $6.node
case *stmt.AltForeach :
n.Expr = $3
n.Key = $5.node
n.ByRef = $6.byRef
n.Variable = $6.node
} }
} }
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $8.node))
$$ = $8
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $8))
yylex.(*Parser).comments.AddComments($$, $1.Comments()) yylex.(*Parser).comments.AddComments($$, $1.Comments())
} }
| T_FOREACH '(' expr_without_variable T_AS foreach_variable foreach_optional_arg ')' foreach_statement | T_FOREACH '(' expr_without_variable T_AS foreach_variable foreach_optional_arg ')' foreach_statement
{ {
if $6.node == nil { if $6.node == nil {
if ($8.isAlt) { switch n := $8.(type) {
$$ = stmt.NewAltForeach($3, nil, $5.node, $8.node, $5.byRef) case *stmt.Foreach :
} else { n.Expr = $3
$$ = stmt.NewForeach($3, nil, $5.node, $8.node, $5.byRef) n.ByRef = $5.byRef
n.Variable = $5.node
case *stmt.AltForeach :
n.Expr = $3
n.ByRef = $5.byRef
n.Variable = $5.node
} }
} else { } else {
if ($8.isAlt) { switch n := $8.(type) {
$$ = stmt.NewAltForeach($3, $5.node, $6.node, $8.node, $6.byRef) case *stmt.Foreach :
} else { n.Expr = $3
$$ = stmt.NewForeach($3, $5.node, $6.node, $8.node, $6.byRef) n.Key = $5.node
n.ByRef = $6.byRef
n.Variable = $6.node
case *stmt.AltForeach :
n.Expr = $3
n.Key = $5.node
n.ByRef = $6.byRef
n.Variable = $6.node
} }
} }
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $8.node))
$$ = $8
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $8))
yylex.(*Parser).comments.AddComments($$, $1.Comments()) yylex.(*Parser).comments.AddComments($$, $1.Comments())
} }
| T_DECLARE '(' declare_list ')' declare_statement | T_DECLARE '(' declare_list ')' declare_statement
@ -1097,22 +1138,34 @@ foreach_variable:
for_statement: for_statement:
statement statement
{ $$ = altSyntaxNode{$1, false} } {
$$ = stmt.NewFor(nil, nil, nil, $1)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodePosition($1))
}
| ':' inner_statement_list T_ENDFOR ';' | ':' inner_statement_list T_ENDFOR ';'
{ {
$$ = altSyntaxNode{stmt.NewStmtList($2), true} stmtList := stmt.NewStmtList($2)
yylex.(*Parser).positions.AddPosition($$.node, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4)) $$ = stmt.NewAltFor(nil, nil, nil, stmtList)
yylex.(*Parser).positions.AddPosition(stmtList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
} }
; ;
foreach_statement: foreach_statement:
statement statement
{ $$ = altSyntaxNode{$1, false} } {
$$ = stmt.NewForeach(nil, nil, nil, $1, false)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodePosition($1))
}
| ':' inner_statement_list T_ENDFOREACH ';' | ':' inner_statement_list T_ENDFOREACH ';'
{ {
$$ = altSyntaxNode{stmt.NewStmtList($2), true} stmtList := stmt.NewStmtList($2)
yylex.(*Parser).positions.AddPosition($$.node, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4)) $$ = stmt.NewAltForeach(nil, nil, nil, stmtList, false)
yylex.(*Parser).positions.AddPosition(stmtList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
} }
; ;
@ -1222,11 +1275,17 @@ case_separator:
while_statement: while_statement:
statement statement
{ $$ = altSyntaxNode{$1, false} } {
$$ = stmt.NewWhile(nil, $1)
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodePosition($1))
}
| ':' inner_statement_list T_ENDWHILE ';' | ':' inner_statement_list T_ENDWHILE ';'
{ {
$$ = altSyntaxNode{stmt.NewStmtList($2), true} stmtList := stmt.NewStmtList($2)
yylex.(*Parser).positions.AddPosition($$.node, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4)) $$ = stmt.NewAltWhile(nil, stmtList)
yylex.(*Parser).positions.AddPosition(stmtList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
} }
; ;
@ -3948,8 +4007,3 @@ type simpleIndirectReference struct {
all []*expr.Variable all []*expr.Variable
last *expr.Variable last *expr.Variable
} }
type altSyntaxNode struct {
node node.Node
isAlt bool
}

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,6 @@ import (
list []node.Node list []node.Node
foreachVariable foreachVariable foreachVariable foreachVariable
str string str string
altSyntaxNode altSyntaxNode
} }
%type <token> $unk %type <token> $unk
@ -266,6 +265,7 @@ import (
%type <node> trait_adaptations %type <node> trait_adaptations
%type <node> switch_case_list %type <node> switch_case_list
%type <node> method_body %type <node> method_body
%type <node> foreach_statement for_statement while_statement
%type <node> member_modifier %type <node> member_modifier
%type <node> use_type %type <node> use_type
@ -284,8 +284,6 @@ import (
%type <str> backup_doc_comment %type <str> backup_doc_comment
%type <altSyntaxNode> while_statement for_statement foreach_statement
%% %%
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
@ -775,14 +773,17 @@ statement:
{ $$ = $1; } { $$ = $1; }
| T_WHILE '(' expr ')' while_statement | T_WHILE '(' expr ')' while_statement
{ {
if ($5.isAlt) { switch n := $5.(type) {
$$ = stmt.NewAltWhile($3, $5.node) case *stmt.While :
} else { n.Cond = $3
$$ = stmt.NewWhile($3, $5.node) case *stmt.AltWhile :
n.Cond = $3
} }
$$ = $5
// save position // save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $5.node)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $5))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.WhileToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.WhileToken)
@ -805,14 +806,21 @@ statement:
} }
| T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement | T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement
{ {
if ($9.isAlt) { switch n := $9.(type) {
$$ = stmt.NewAltFor($3, $5, $7, $9.node) case *stmt.For :
} else { n.Init = $3
$$ = stmt.NewFor($3, $5, $7, $9.node) n.Cond = $5
n.Loop = $7
case *stmt.AltFor :
n.Init = $3
n.Cond = $5
n.Loop = $7
} }
$$ = $9
// save position // save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9.node)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ForToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.ForToken)
@ -946,14 +954,21 @@ statement:
} }
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
{ {
if ($7.isAlt) { switch n := $7.(type) {
$$ = stmt.NewAltForeach($3, nil, $5.node, $7.node, $5.byRef) case *stmt.Foreach :
} else { n.Expr = $3
$$ = stmt.NewForeach($3, nil, $5.node, $7.node, $5.byRef) n.ByRef = $5.byRef
n.Variable = $5.node
case *stmt.AltForeach :
n.Expr = $3
n.ByRef = $5.byRef
n.Variable = $5.node
} }
$$ = $7
// save position // save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $7.node)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $7))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ForeachToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.ForeachToken)
@ -963,14 +978,23 @@ statement:
} }
| T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement | T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement
{ {
if ($9.isAlt) { switch n := $9.(type) {
$$ = stmt.NewAltForeach($3, $5, $7.node, $9.node, $7.byRef) case *stmt.Foreach :
} else { n.Expr = $3
$$ = stmt.NewForeach($3, $5, $7.node, $9.node, $7.byRef) n.Key = $5
n.ByRef = $7.byRef
n.Variable = $7.node
case *stmt.AltForeach :
n.Expr = $3
n.Key = $5
n.ByRef = $7.byRef
n.Variable = $7.node
} }
$$ = $9
// save position // save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9.node)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $9))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ForeachToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.ForeachToken)
@ -1354,35 +1378,49 @@ foreach_variable:
for_statement: for_statement:
statement statement
{ $$ = altSyntaxNode{$1, false} }
| ':' inner_statement_list T_ENDFOR ';'
{ {
$$ = altSyntaxNode{stmt.NewStmtList($2), true} $$ = stmt.NewFor(nil, nil, nil, $1)
// save position // save position
yylex.(*Parser).positions.AddPosition($$.node, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodePosition($1))
}
| ':' inner_statement_list T_ENDFOR ';'
{
stmtList := stmt.NewStmtList($2)
$$ = stmt.NewAltFor(nil, nil, nil, stmtList)
// save position
yylex.(*Parser).positions.AddPosition(stmtList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$.node, $1, comment.ColonToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.ColonToken)
yylex.(*Parser).comments.AddFromToken($$.node, $3, comment.EndforToken) yylex.(*Parser).comments.AddFromToken($$, $3, comment.EndforToken)
yylex.(*Parser).comments.AddFromToken($$.node, $4, comment.SemiColonToken) yylex.(*Parser).comments.AddFromToken($$, $4, comment.SemiColonToken)
} }
; ;
foreach_statement: foreach_statement:
statement statement
{ $$ = altSyntaxNode{$1, false} }
| ':' inner_statement_list T_ENDFOREACH ';'
{ {
$$ = altSyntaxNode{stmt.NewStmtList($2), true} $$ = stmt.NewForeach(nil, nil, nil, $1, false)
// save position // save position
yylex.(*Parser).positions.AddPosition($$.node, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodePosition($1))
}
| ':' inner_statement_list T_ENDFOREACH ';'
{
stmtList := stmt.NewStmtList($2)
$$ = stmt.NewAltForeach(nil, nil, nil, stmtList, false)
// save position
yylex.(*Parser).positions.AddPosition(stmtList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$.node, $1, comment.ColonToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.ColonToken)
yylex.(*Parser).comments.AddFromToken($$.node, $3, comment.EndforeachToken) yylex.(*Parser).comments.AddFromToken($$, $3, comment.EndforeachToken)
yylex.(*Parser).comments.AddFromToken($$.node, $4, comment.SemiColonToken) yylex.(*Parser).comments.AddFromToken($$, $4, comment.SemiColonToken)
} }
; ;
@ -1501,18 +1539,25 @@ case_separator:
while_statement: while_statement:
statement statement
{ $$ = altSyntaxNode{$1, false} }
| ':' inner_statement_list T_ENDWHILE ';'
{ {
$$ = altSyntaxNode{stmt.NewStmtList($2), true} $$ = stmt.NewWhile(nil, $1)
// save position // save position
yylex.(*Parser).positions.AddPosition($$.node, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4)) yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodePosition($1))
}
| ':' inner_statement_list T_ENDWHILE ';'
{
stmtList := stmt.NewStmtList($2)
$$ = stmt.NewAltWhile(nil, stmtList)
// save position
yylex.(*Parser).positions.AddPosition(stmtList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
// save comments // save comments
yylex.(*Parser).comments.AddFromToken($$.node, $1, comment.ColonToken) yylex.(*Parser).comments.AddFromToken($$, $1, comment.ColonToken)
yylex.(*Parser).comments.AddFromToken($$.node, $3, comment.EndwhileToken) yylex.(*Parser).comments.AddFromToken($$, $3, comment.EndwhileToken)
yylex.(*Parser).comments.AddFromToken($$.node, $4, comment.SemiColonToken) yylex.(*Parser).comments.AddFromToken($$, $4, comment.SemiColonToken)
} }
; ;
@ -4249,8 +4294,3 @@ type boolWithToken struct {
value bool value bool
token *scanner.Token token *scanner.Token
} }
type altSyntaxNode struct {
node node.Node
isAlt bool
}