remove nodesWithEndToken type

This commit is contained in:
z7zmey
2018-06-03 09:35:44 +03:00
parent 2abe1dfb84
commit a488f43496
17 changed files with 1393 additions and 1251 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,6 @@ import (
boolWithToken boolWithToken
list []node.Node
foreachVariable foreachVariable
nodesWithEndToken *nodesWithEndToken
str string
altSyntaxNode altSyntaxNode
}
@@ -266,12 +265,12 @@ import (
%type <node> argument_list ctor_arguments
%type <node> trait_adaptations
%type <node> switch_case_list
%type <node> method_body
%type <node> member_modifier
%type <node> use_type
%type <foreachVariable> foreach_variable
%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
@@ -1945,11 +1944,15 @@ class_statement:
| method_modifiers T_FUNCTION returns_ref identifier backup_doc_comment '(' parameter_list ')' return_type method_body
{
name := node.NewIdentifier($4.Value)
$$ = stmt.NewClassMethod(name, $1, $3.value, $7, $9, $10.nodes, $5)
$$ = stmt.NewClassMethod(name, $1, $3.value, $7, $9, $10, $5)
// save position
yylex.(*Parser).positions.AddPosition(name, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewOptionalListTokensPosition($1, $2, $10.endToken))
if $1 == nil {
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($2, $10))
} else {
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodeListNodePosition($1, $10))
}
// save comments
yylex.(*Parser).comments.AddFromToken($$, $2, comment.FunctionToken)
@@ -2130,8 +2133,27 @@ absolute_trait_method_reference:
;
method_body:
';' /* abstract method */ { $$ = &nodesWithEndToken{nil, $1} }
| '{' inner_statement_list '}' { $$ = &nodesWithEndToken{$2, $3} }
';' /* abstract method */
{
$$ = stmt.NewNop()
// save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenPosition($1))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.SemiColonToken)
}
| '{' inner_statement_list '}'
{
$$ = stmt.NewStmtList($2)
// save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $3, comment.CloseCurlyBracesToken)
}
;
variable_modifiers:
@@ -4223,11 +4245,6 @@ type foreachVariable struct {
byRef bool
}
type nodesWithEndToken struct {
nodes []node.Node
endToken *scanner.Token
}
type boolWithToken struct {
value bool
token *scanner.Token

View File

@@ -549,7 +549,9 @@ func TestPhp7(t *testing.T) {
MethodName: &node.Identifier{Value: "foo"},
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
Params: expectedParams,
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -866,7 +868,9 @@ func TestPhp7(t *testing.T) {
&stmt.ClassMethod{
PhpDocComment: "",
MethodName: &node.Identifier{Value: "bar"},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -881,7 +885,9 @@ func TestPhp7(t *testing.T) {
&node.Identifier{Value: "public"},
&node.Identifier{Value: "static"},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -901,7 +907,9 @@ func TestPhp7(t *testing.T) {
&name.NamePart{Value: "void"},
},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -2966,7 +2974,9 @@ func TestPhp7(t *testing.T) {
&stmt.ClassMethod{
MethodName: &node.Identifier{Value: "class"},
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},
@@ -3072,6 +3082,7 @@ func TestPhp7(t *testing.T) {
&node.Identifier{Value: "protected"},
&node.Identifier{Value: "static"},
},
Stmt: &stmt.Nop{},
},
&stmt.ClassMethod{
MethodName: &node.Identifier{Value: "baz"},
@@ -3079,7 +3090,9 @@ func TestPhp7(t *testing.T) {
&node.Identifier{Value: "final"},
&node.Identifier{Value: "private"},
},
Stmts: []node.Node{},
Stmt: &stmt.StmtList{
Stmts: []node.Node{},
},
},
},
},