1
-
2
- / *
1
+ /* zephir.lemon
2
+ *
3
3
* This file is part of the Zephir Parser.
4
4
*
5
5
* (c) Zephir Team <
[email protected] >
6
6
*
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
7
+ * For the full copyright and license information, please view
8
+ * the LICENSE file that was distributed with this source code.
9
9
*/
10
10
11
11
%token_prefix XX_
12
12
%token_type {xx_parser_token*}
13
13
%default_type {zval}
14
+ %default_destructor {
15
+ if (&$$) {
16
+ zval_ptr_dtor(&$$);
17
+ }
18
+ }
14
19
%extra_argument {xx_parser_status *status}
15
20
%name xx_
16
21
71
76
if ($$->free_flag) {
72
77
efree($$->token);
73
78
}
79
+ efree($$);
74
80
}
75
81
}
76
82
@@ -79,8 +85,9 @@ program ::= xx_language(Q) . {
79
85
}
80
86
81
87
%destructor xx_language {
82
- //zval_ptr_dtor($$);
83
- //efree($$);
88
+ if (&$$) {
89
+ zval_ptr_dtor(&$$);
90
+ }
84
91
}
85
92
86
93
xx_language(R) ::= xx_top_statement_list(L) . {
@@ -265,6 +272,8 @@ xx_class_def(R) ::= FINAL CLASS IDENTIFIER(I) EXTENDS IDENTIFIER(E) IMPLEMENTS x
265
272
xx_ret_class(&R, I, &B, 0, 1, E, &L, status->scanner_state);
266
273
}
267
274
275
+ /* TODO: Add internall class */
276
+
268
277
xx_class_body(R) ::= BRACKET_OPEN BRACKET_CLOSE . {
269
278
ZVAL_UNDEF(&R);
270
279
}
@@ -2082,27 +2091,78 @@ xx_call_parameter(R) ::= IDENTIFIER(I) COLON xx_common_expr(E) . {
2082
2091
xx_ret_call_parameter(&R, I, &E, status->scanner_state);
2083
2092
}
2084
2093
2085
- /** empty closure function () { } * */
2094
+ /* empty closure function () { } */
2086
2095
xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
2087
- xx_ret_expr (&R, "closure" , NULL, NULL, NULL, status->scanner_state);
2096
+ xx_ret_closure (&R, NULL, NULL, NULL, status->scanner_state);
2088
2097
}
2089
2098
2090
- /** function() { ... }*/
2099
+ /* empty closure with "use":
2100
+ function () use (a, b, c) { } */
2101
+ xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list(U) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
2102
+ xx_ret_closure(&R, NULL, NULL, &U, status->scanner_state);
2103
+ }
2104
+
2105
+ /* function() { ... } */
2091
2106
xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(S) BRACKET_CLOSE . {
2092
- xx_ret_expr (&R, "closure" , NULL, &S, NULL, status->scanner_state);
2107
+ xx_ret_closure (&R, NULL, &S, NULL, status->scanner_state);
2093
2108
}
2094
2109
2095
- /** function(a, b, c) { }*/
2110
+ /* function() use (a, b, c) { ... } */
2111
+ xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list(U) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(S) BRACKET_CLOSE . {
2112
+ xx_ret_closure(&R, NULL, &S, &U, status->scanner_state);
2113
+ }
2114
+
2115
+ /* function(a, b, c) { } */
2096
2116
xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN xx_parameter_list(L) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
2097
- xx_ret_expr(&R, "closure", &L, NULL, NULL, status->scanner_state);
2117
+ xx_ret_closure(&R, &L, NULL, NULL, status->scanner_state);
2118
+ }
2119
+
2120
+ /* function(a, b, c) use (a, b, c) { } */
2121
+ xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN xx_parameter_list(L) PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list(U) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
2122
+ xx_ret_closure(&R, &L, NULL, &U, status->scanner_state);
2098
2123
}
2099
2124
2100
- /** function(a, b, c) { ... }*/
2125
+ /* function(a, b, c) { ... } */
2101
2126
xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN xx_parameter_list(L) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(S) BRACKET_CLOSE . {
2102
- xx_ret_expr(&R, "closure", &L, &S, NULL, status->scanner_state);
2127
+ xx_ret_closure(&R, &L, &S, NULL, status->scanner_state);
2128
+ }
2129
+
2130
+ /* function(a, b, c) use (a, b, c) { ... } */
2131
+ xx_common_expr(R) ::= FUNCTION PARENTHESES_OPEN xx_parameter_list(L) PARENTHESES_CLOSE USE PARENTHESES_OPEN xx_use_parameter_list(U) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(S) BRACKET_CLOSE . {
2132
+ xx_ret_closure(&R, &L, &S, &U, status->scanner_state);
2133
+ }
2134
+
2135
+ /* xx_use_parameter_list */
2136
+
2137
+ xx_use_parameter_list(R) ::= xx_use_parameter_list(L) COMMA xx_use_parameter(P) . {
2138
+ xx_ret_list(&R, &L, &P, status->scanner_state);
2139
+ }
2140
+
2141
+ xx_use_parameter_list(R) ::= xx_use_parameter(P) . {
2142
+ xx_ret_list(&R, NULL, &P, status->scanner_state);
2143
+ }
2144
+
2145
+ // a
2146
+ xx_use_parameter(R) ::= IDENTIFIER(I) . {
2147
+ xx_ret_parameter(&R, 0, NULL, NULL, I, NULL, 0, 0, status->scanner_state);
2148
+ }
2149
+
2150
+ // &a
2151
+ xx_use_parameter(R) ::= BITWISE_AND IDENTIFIER(I) . {
2152
+ xx_ret_parameter(&R, 0, NULL, NULL, I, NULL, 0, 1, status->scanner_state);
2153
+ }
2154
+
2155
+ // const a
2156
+ xx_use_parameter(R) ::= CONST IDENTIFIER(I) . {
2157
+ xx_ret_parameter(&R, 1, NULL, NULL, I, NULL, 0, 0, status->scanner_state);
2158
+ }
2159
+
2160
+ // const &a
2161
+ xx_use_parameter(R) ::= CONST BITWISE_AND IDENTIFIER(I) . {
2162
+ xx_ret_parameter(&R, 1, NULL, NULL, I, NULL, 0, 1, status->scanner_state);
2103
2163
}
2104
2164
2105
- /** x => x + 1 */
2165
+ /* x => x + 1 */
2106
2166
xx_common_expr(R) ::= IDENTIFIER(I) DOUBLEARROW xx_common_expr(E) . {
2107
2167
{
2108
2168
zval identifier;
0 commit comments