create CaseList node
This commit is contained in:
1076
php7/php7.go
1076
php7/php7.go
File diff suppressed because it is too large
Load Diff
79
php7/php7.y
79
php7/php7.y
@@ -265,12 +265,13 @@ import (
|
||||
%type <node> class_modifier
|
||||
%type <node> argument_list ctor_arguments
|
||||
%type <node> trait_adaptations
|
||||
%type <node> switch_case_list
|
||||
|
||||
%type <node> member_modifier
|
||||
%type <node> use_type
|
||||
%type <foreachVariable> foreach_variable
|
||||
|
||||
%type <nodesWithEndToken> method_body switch_case_list
|
||||
%type <nodesWithEndToken> method_body
|
||||
|
||||
%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 global_var_list
|
||||
@@ -823,14 +824,19 @@ statement:
|
||||
}
|
||||
| T_SWITCH '(' expr ')' switch_case_list
|
||||
{
|
||||
if ($5.endToken.Value == ";") {
|
||||
$$ = stmt.NewAltSwitch($3, $5.nodes)
|
||||
} else {
|
||||
$$ = stmt.NewSwitch($3, $5.nodes)
|
||||
switch n := $5.(type) {
|
||||
case *stmt.Switch:
|
||||
n.Cond = $3
|
||||
case *stmt.AltSwitch:
|
||||
n.Cond = $3
|
||||
default:
|
||||
panic("unexpected node type")
|
||||
}
|
||||
|
||||
$$ = $5
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $5.endToken))
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $5))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken($$, $1, comment.SwitchToken)
|
||||
@@ -1399,10 +1405,63 @@ declare_statement:
|
||||
;
|
||||
|
||||
switch_case_list:
|
||||
'{' case_list '}' { $$ = &nodesWithEndToken{$2, $3} }
|
||||
| '{' ';' case_list '}' { $$ = &nodesWithEndToken{$3, $4} }
|
||||
| ':' case_list T_ENDSWITCH ';' { $$ = &nodesWithEndToken{$2, $4} }
|
||||
| ':' ';' case_list T_ENDSWITCH ';' { $$ = &nodesWithEndToken{$3, $5} }
|
||||
'{' case_list '}'
|
||||
{
|
||||
caseList := stmt.NewCaseList($2)
|
||||
$$ = stmt.NewSwitch(nil, caseList)
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition(caseList, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $1, comment.OpenCurlyBracesToken)
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $3, comment.CloseCurlyBracesToken)
|
||||
}
|
||||
| '{' ';' case_list '}'
|
||||
{
|
||||
caseList := stmt.NewCaseList($3)
|
||||
$$ = stmt.NewSwitch(nil, caseList)
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition(caseList, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $1, comment.OpenCurlyBracesToken)
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $2, comment.SemiColonToken)
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $4, comment.CloseCurlyBracesToken)
|
||||
}
|
||||
| ':' case_list T_ENDSWITCH ';'
|
||||
{
|
||||
caseList := stmt.NewCaseList($2)
|
||||
$$ = stmt.NewAltSwitch(nil, caseList)
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition(caseList, yylex.(*Parser).positionBuilder.NewNodeListPosition($2))
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $4))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $1, comment.ColonToken)
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $3, comment.EndswitchToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $4, comment.SemiColonToken)
|
||||
}
|
||||
| ':' ';' case_list T_ENDSWITCH ';'
|
||||
{
|
||||
|
||||
caseList := stmt.NewCaseList($3)
|
||||
$$ = stmt.NewAltSwitch(nil, caseList)
|
||||
|
||||
// save position
|
||||
yylex.(*Parser).positions.AddPosition(caseList, yylex.(*Parser).positionBuilder.NewNodeListPosition($3))
|
||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $5))
|
||||
|
||||
// save comments
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $1, comment.ColonToken)
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $2, comment.SemiColonToken)
|
||||
yylex.(*Parser).comments.AddFromToken(caseList, $4, comment.EndswitchToken)
|
||||
yylex.(*Parser).comments.AddFromToken($$, $5, comment.SemiColonToken)
|
||||
}
|
||||
;
|
||||
|
||||
case_list:
|
||||
|
||||
@@ -1381,63 +1381,71 @@ func TestPhp7(t *testing.T) {
|
||||
},
|
||||
&stmt.AltSwitch{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Default{
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{},
|
||||
CaseList: &stmt.CaseList{
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Default{
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.AltSwitch{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Switch{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
CaseList: &stmt.CaseList{
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Switch{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
CaseList: &stmt.CaseList{
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
},
|
||||
},
|
||||
&stmt.Switch{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
CaseList: &stmt.CaseList{
|
||||
Cases: []node.Node{
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "1"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
},
|
||||
},
|
||||
&stmt.Case{
|
||||
Cond: &scalar.Lnumber{Value: "2"},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Break{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user