Skip to content

Instantly share code, notes, and snippets.

@krakjoe
Last active January 3, 2016 11:39
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 krakjoe/8458028 to your computer and use it in GitHub Desktop.
Save krakjoe/8458028 to your computer and use it in GitHub Desktop.
generics-parser.patch
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 752e27f..989296d 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -45,7 +45,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%}
%pure_parser
-%expect 3
+%expect 5
%code requires {
#ifdef ZTS
@@ -413,13 +413,29 @@ unticked_function_declaration_statement:
'{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); }
;
+generic_type:
+ T_ARRAY { $$.op_type = IS_CONST; Z_TYPE($$.u.constant)=IS_ARRAY; }
+ | T_CALLABLE { $$.op_type = IS_CONST; Z_TYPE($$.u.constant)=IS_CALLABLE; }
+ | fully_qualified_class_name { $$ = $1; }
+;
+
+generic_declaration:
+ generic_type
+ | generic_declaration ',' generic_type
+;
+
+optional_generic_types:
+ '<' generic_declaration '>' { $$ = $2; }
+ | /* empty */ { $$.op_type = IS_UNUSED; }
+;
+
unticked_class_declaration_statement:
- class_entry_type T_STRING extends_from
- { zend_do_begin_class_declaration(&$1, &$2, &$3 TSRMLS_CC); }
+ class_entry_type T_STRING optional_generic_types extends_from
+ { zend_do_begin_class_declaration(&$1, &$2, &$4 TSRMLS_CC); }
implements_list
'{'
class_statement_list
- '}' { zend_do_end_class_declaration(&$1, &$3 TSRMLS_CC); }
+ '}' { zend_do_end_class_declaration(&$1, &$4 TSRMLS_CC); }
| interface_entry T_STRING
{ zend_do_begin_class_declaration(&$1, &$2, NULL TSRMLS_CC); }
interface_extends_list
@@ -918,6 +934,8 @@ fully_qualified_class_name:
class_name_reference:
class_name { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
| dynamic_class_name_reference { zend_do_end_variable_parse(&$1, BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
+ | class_name '<' generic_declaration '>' { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
+ | dynamic_class_name_reference '<' generic_declaration '>' { zend_do_end_variable_parse(&$1, BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment