parse class implements, extends

This commit is contained in:
vadim 2017-11-30 19:35:13 +02:00
parent 38c49ffa03
commit 6b7bf8b2af
2 changed files with 1674 additions and 1612 deletions

3247
parser.go

File diff suppressed because it is too large Load Diff

View File

@ -292,6 +292,8 @@ func (n node) attribute(key string, value string) node {
%type <node> trait_declaration_statement %type <node> trait_declaration_statement
%type <node> interface_declaration_statement %type <node> interface_declaration_statement
%type <node> interface_extends_list %type <node> interface_extends_list
%type <node> extends_from
%type <node> implements_list
%% %%
@ -671,9 +673,23 @@ possible_comma:
; ;
class_declaration_statement: class_declaration_statement:
class_modifiers T_CLASS T_STRING '{' class_statement_list '}' class_modifiers T_CLASS T_STRING extends_from implements_list '{' class_statement_list '}'
{ $$ = $1.attribute("name", $3).append($5) } {
| T_CLASS T_STRING '{' class_statement_list '}' { $$ = Node("Class").attribute("name", $2).append($4) } $$ = Node("Class").
attribute("name", $3).
append($1).
append(Node("Extends").append($4)).
append(Node("Implements").append($5)).
append($7);
}
| T_CLASS T_STRING extends_from implements_list '{' class_statement_list '}'
{
$$ = Node("Class").
attribute("name", $2).
append(Node("Extends").append($3)).
append(Node("Implements").append($4)).
append($6);
}
; ;
class_modifiers: class_modifiers:
@ -700,11 +716,21 @@ interface_declaration_statement:
} }
; ;
extends_from:
/* empty */ { $$ = Node(""); }
| T_EXTENDS name { $$ = $2; }
;
interface_extends_list: interface_extends_list:
/* empty */ { $$ = Node("") } /* empty */ { $$ = Node("") }
| T_EXTENDS name_list { $$ = $2; } | T_EXTENDS name_list { $$ = $2; }
; ;
implements_list:
/* empty */ { $$ = Node(""); }
| T_IMPLEMENTS name_list { $$ = $2; }
;
class_statement_list: class_statement_list:
class_statement_list class_statement { $$ = $1.append($2) } class_statement_list class_statement { $$ = $1.append($2) }
| /* empty */ { $$ = Node("Stmt") } | /* empty */ { $$ = Node("Stmt") }
@ -1083,9 +1109,12 @@ static_member:
%% %%
const src = `<?php const src = `<?php
interface foo extends A, B class foo extends A implements B, C
{ {
private static function bar($a = null); private static function bar($a = null)
{
}
} }
` `