Skip to content

Instantly share code, notes, and snippets.

@brzuchal
Created June 7, 2017 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brzuchal/66873c598c3c9095d635485081209568 to your computer and use it in GitHub Desktop.
Save brzuchal/66873c598c3c9095d635485081209568 to your computer and use it in GitHub Desktop.
Closure Syntax
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 92524c6..8ac8f55 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -240,7 +240,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> internal_functions_in_yacc
%type <ast> exit_expr scalar backticks_expr lexical_var function_call member_name property_name
%type <ast> variable_class_name dereferencable_scalar constant dereferencable
-%type <ast> callable_expr callable_variable static_member new_variable
+%type <ast> callable_expr callable_variable static_member new_variable closure_expr
%type <ast> encaps_var encaps_var_offset isset_variables
%type <ast> top_statement_list use_declarations const_list inner_statement_list if_stmt
%type <ast> alt_if_stmt for_exprs switch_case_list global_var_list static_var_list
@@ -1117,6 +1117,7 @@ callable_expr:
callable_variable { $$ = $1; }
| '(' expr ')' { $$ = $2; }
| dereferencable_scalar { $$ = $1; }
+ | '{' closure_expr '}' { $$ = $2; }
;
callable_variable:
@@ -1133,6 +1134,17 @@ callable_variable:
| function_call { $$ = $1; }
;
+closure_expr:
+ name
+ { $$ = $1; }
+ | simple_variable
+ { $$ = zend_ast_create(ZEND_AST_VAR, $1); }
+ | dereferencable T_OBJECT_OPERATOR property_name
+ { $$ = zend_ast_create(ZEND_AST_PROP, $1, $3); }
+ | class_name T_PAAMAYIM_NEKUDOTAYIM identifier
+ { $$ = zend_ast_create(ZEND_AST_METHOD_REFERENCE, $1, $3); }
+;
+
variable:
callable_variable
{ $$ = $1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment