From ccacd37dee4e2f5c9ae2445de3abed762a280039 Mon Sep 17 00:00:00 2001 From: vadim Date: Thu, 30 Nov 2017 20:07:45 +0200 Subject: [PATCH] parse calls --- parser.go | 4269 ++++++++++++++++++++++++++++------------------------- parser.y | 53 +- 2 files changed, 2299 insertions(+), 2023 deletions(-) diff --git a/parser.go b/parser.go index e0d5003..5fa7b46 100644 --- a/parser.go +++ b/parser.go @@ -367,9 +367,9 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line parser.y:1110 +//line parser.y:1159 const src = ` interface_extends_list %type extends_from %type implements_list +%type argument_list +%type non_empty_argument_list +%type argument +%type callable_expr +%type function_call +%type member_name %% @@ -412,6 +418,9 @@ inner_statement: statement { $$ = $1; } | function_declaration_statement { $$ = $1; } | class_declaration_statement { $$ = $1; } + | trait_declaration_statement { $$ = $1; } + | interface_declaration_statement { $$ = $1; } + | T_HALT_COMPILER '(' ')' ';' { $$ = Node("THaltCompiler") } statement: '{' inner_statement_list '}' { $$ = $2; } @@ -464,7 +473,7 @@ statement: append($9); } | T_DECLARE '(' const_list ')' declare_statement { $$ = Node("Declare").append($3).append($5) } - | ';' /* empty statement */ { $$ = Node(""); } + | ';' /* empty statement */ { $$ = Node(""); } | T_TRY '{' inner_statement_list '}' catch_list finally_statement { $$ = Node("Try"). @@ -1060,6 +1069,12 @@ dereferencable: | dereferencable_scalar { $$ = $1; } ; +callable_expr: + callable_variable { $$ = $1; } + | '(' expr ')' { $$ = $2; } + | dereferencable_scalar { $$ = $1; } +; + dereferencable_scalar: T_ARRAY '(' array_pair_list ')' { $$ = $3; } | '[' array_pair_list ']' { $$ = $2; } @@ -1078,6 +1093,40 @@ optional_expr: callable_variable: simple_variable { $$ = $1; } + | dereferencable '[' optional_expr ']' { $$ = Node("Dim").append($1).append($3)} + | constant '[' optional_expr ']' { $$ = Node("Dim").append($1).append($3)} + | dereferencable '{' expr '}' { $$ = Node("Dim").append($1).append($3)} + | dereferencable T_OBJECT_OPERATOR property_name argument_list + { $$ = Node("MethodCall").append($1).append($3).append($4)} + | function_call { $$ = $1; } +; + +function_call: + name argument_list { $$ = Node("FunctionCall").append($1).append($2) } + | class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list + { $$ = Node("StaticCall").append($1).append($3).append($4) } + | variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list + { $$ = Node("StaticCall").append($1).append($3).append($4) } + | callable_expr argument_list { $$ = Node("Call").append($1).append($2); } +; + +member_name: + identifier { $$ = $1; } + | '{' expr '}' { $$ = $2; } + | simple_variable { $$ = $1 } +; + +argument_list: + '(' ')' { $$ = Node("ArgumentList") } + | '(' non_empty_argument_list possible_comma ')' { $$ = $2; } +; +non_empty_argument_list: + argument { $$ = Node("ArgumentList").append($1) } + | non_empty_argument_list ',' argument { $$ = $1.append($3) } +; +argument: + expr { $$ = $1; } + | T_ELLIPSIS expr { $$ = Node("Unpack").append($2) } ; variable: @@ -1110,7 +1159,7 @@ static_member: %% const src = `