1-
2- / *
1+ /* zephir.lemon
2+ *
33 * This file is part of the Zephir Parser.
44 *
55 * (c) Zephir Team <team@zephir-lang.com>
66 *
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.
99 */
1010
1111%token_prefix XX_
1212%token_type {xx_parser_token*}
1313%default_type {zval}
14+ %default_destructor {
15+ if (&$$) {
16+ zval_ptr_dtor(&$$);
17+ }
18+ }
1419%extra_argument {xx_parser_status *status}
1520%name xx_
1621
7176 if ($$->free_flag) {
7277 efree($$->token);
7378 }
79+ efree($$);
7480 }
7581}
7682
@@ -79,8 +85,9 @@ program ::= xx_language(Q) . {
7985}
8086
8187%destructor xx_language {
82- //zval_ptr_dtor($$);
83- //efree($$);
88+ if (&$$) {
89+ zval_ptr_dtor(&$$);
90+ }
8491}
8592
8693xx_language(R) ::= xx_top_statement_list(L) . {
@@ -265,6 +272,8 @@ xx_class_def(R) ::= FINAL CLASS IDENTIFIER(I) EXTENDS IDENTIFIER(E) IMPLEMENTS x
265272 xx_ret_class(&R, I, &B, 0, 1, E, &L, status->scanner_state);
266273}
267274
275+ /* TODO: Add internall class */
276+
268277xx_class_body(R) ::= BRACKET_OPEN BRACKET_CLOSE . {
269278 ZVAL_UNDEF(&R);
270279}
@@ -2082,27 +2091,78 @@ xx_call_parameter(R) ::= IDENTIFIER(I) COLON xx_common_expr(E) . {
20822091 xx_ret_call_parameter(&R, I, &E, status->scanner_state);
20832092}
20842093
2085- /** empty closure function () { } * */
2094+ /* empty closure function () { } */
20862095xx_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);
20882097}
20892098
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() { ... } */
20912106xx_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);
20932108}
20942109
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) { } */
20962116xx_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);
20982123}
20992124
2100- /** function(a, b, c) { ... }*/
2125+ /* function(a, b, c) { ... } */
21012126xx_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);
21032163}
21042164
2105- /** x => x + 1 */
2165+ /* x => x + 1 */
21062166xx_common_expr(R) ::= IDENTIFIER(I) DOUBLEARROW xx_common_expr(E) . {
21072167 {
21082168 zval identifier;
0 commit comments