create ClassExtends ClassImplements InterfaceExtends nodes

This commit is contained in:
z7zmey
2018-05-12 23:10:01 +03:00
parent cf4fb26764
commit ac74ae3225
19 changed files with 1720 additions and 1495 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -20,11 +20,15 @@ import (
%}
%union{
node node.Node
token *scanner.Token
list []node.Node
foreachVariable foreachVariable
str string
node node.Node
token *scanner.Token
list []node.Node
foreachVariable foreachVariable
str string
ClassExtends *stmt.ClassExtends
ClassImplements *stmt.ClassImplements
InterfaceExtends *stmt.InterfaceExtends
}
%type <token> $unk
@@ -243,7 +247,7 @@ import (
%type <node> const_decl inner_statement
%type <node> expr optional_expr
%type <node> declare_statement finally_statement unset_variable variable
%type <node> extends_from parameter optional_type argument expr_without_variable global_var
%type <node> parameter optional_type argument expr_without_variable global_var
%type <node> static_var class_statement trait_adaptation trait_precedence trait_alias
%type <node> absolute_trait_method_reference trait_method_reference property echo_expr
%type <node> new_expr anonymous_class class_name class_name_reference simple_variable
@@ -265,6 +269,9 @@ import (
%type <node> switch_case_list
%type <node> method_body
%type <node> foreach_statement for_statement while_statement
%type <ClassExtends> extends_from
%type <ClassImplements> implements_list
%type <InterfaceExtends> interface_extends_list
%type <node> member_modifier
%type <node> use_type
@@ -278,7 +285,7 @@ import (
%type <list> use_declarations lexical_var_list lexical_vars isset_variables non_empty_array_pair_list
%type <list> array_pair_list non_empty_argument_list top_statement_list
%type <list> inner_statement_list parameter_list non_empty_parameter_list class_statement_list
%type <list> interface_extends_list implements_list method_modifiers variable_modifiers
%type <list> method_modifiers variable_modifiers
%type <list> non_empty_member_modifiers name_list class_modifiers
%type <str> backup_doc_comment
@@ -1199,12 +1206,6 @@ class_declaration_statement:
// save comments
yylex.(*Parser).comments.AddFromToken($$, $2, comment.ClassToken)
yylex.(*Parser).comments.AddFromToken(name, $3, comment.StringToken)
if $4 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, $4)
}
if $5 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($5))
}
yylex.(*Parser).comments.AddFromToken($$, $7, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $9, comment.CloseCurlyBracesToken)
}
@@ -1220,12 +1221,6 @@ class_declaration_statement:
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ClassToken)
yylex.(*Parser).comments.AddFromToken(name, $2, comment.StringToken)
if $3 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, $3)
}
if $4 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($4))
}
yylex.(*Parser).comments.AddFromToken($$, $6, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $8, comment.CloseCurlyBracesToken)
}
@@ -1292,9 +1287,6 @@ interface_declaration_statement:
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.InterfaceToken)
yylex.(*Parser).comments.AddFromToken(name, $2, comment.StringToken)
if $3 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($3))
}
yylex.(*Parser).comments.AddFromToken($$, $5, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $7, comment.CloseCurlyBracesToken)
}
@@ -1305,7 +1297,10 @@ extends_from:
{ $$ = nil }
| T_EXTENDS name
{
$$ = $2;
$$ = stmt.NewClassExtends($2);
// save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($1, $2))
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ExtendsToken)
@@ -1317,10 +1312,13 @@ interface_extends_list:
{ $$ = nil }
| T_EXTENDS name_list
{
$$ = $2;
$$ = stmt.NewInterfaceExtends($2);
// save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
// save comments
yylex.(*Parser).comments.AddFromToken(firstNode($$), $1, comment.ExtendsToken)
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ExtendsToken)
}
;
@@ -1329,10 +1327,13 @@ implements_list:
{ $$ = nil }
| T_IMPLEMENTS name_list
{
$$ = $2;
$$ = stmt.NewClassImplements($2);
// save position
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodeListPosition($1, $2))
// save comments
yylex.(*Parser).comments.AddFromToken(firstNode($$), $1, comment.ImplementsToken)
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ImplementsToken)
}
;
@@ -2432,12 +2433,6 @@ anonymous_class:
// save comments
yylex.(*Parser).comments.AddFromToken($$, $1, comment.ClassToken)
if $3 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, $3)
}
if $4 != nil {
yylex.(*Parser).comments.AddFromChildNode($$, firstNode($4))
}
yylex.(*Parser).comments.AddFromToken($$, $6, comment.OpenCurlyBracesToken)
yylex.(*Parser).comments.AddFromToken($$, $8, comment.CloseCurlyBracesToken)
}

View File

@@ -925,20 +925,8 @@ func TestPhp7(t *testing.T) {
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
},
Extends: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
},
},
Stmts: []node.Node{},
},
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
},
Implements: []node.Node{
&name.Name{
Extends: &stmt.ClassExtends{
ClassName: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
},
@@ -951,15 +939,33 @@ func TestPhp7(t *testing.T) {
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
},
Implements: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
Implements: &stmt.ClassImplements{
InterfaceNames: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "baz"},
},
Stmts: []node.Node{},
},
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
},
Implements: &stmt.ClassImplements{
InterfaceNames: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "baz"},
},
},
},
},
@@ -970,20 +976,24 @@ func TestPhp7(t *testing.T) {
Class: &stmt.Class{
ArgumentList: &node.ArgumentList{},
Extends: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "foo"},
},
},
Implements: []node.Node{
&name.Name{
Extends: &stmt.ClassExtends{
ClassName: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
&name.NamePart{Value: "foo"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "baz"},
},
Implements: &stmt.ClassImplements{
InterfaceNames: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "bar"},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "baz"},
},
},
},
},
@@ -1294,10 +1304,12 @@ func TestPhp7(t *testing.T) {
&stmt.Interface{
PhpDocComment: "",
InterfaceName: &node.Identifier{Value: "Foo"},
Extends: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
Extends: &stmt.InterfaceExtends{
InterfaceNames: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
},
},
@@ -1306,15 +1318,17 @@ func TestPhp7(t *testing.T) {
&stmt.Interface{
PhpDocComment: "",
InterfaceName: &node.Identifier{Value: "Foo"},
Extends: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
Extends: &stmt.InterfaceExtends{
InterfaceNames: []node.Node{
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
},
},
},
},