Skip to content

Commit e34b7bc

Browse files
authored
Merge pull request #70 from phalcon/development
1.3.0
2 parents 71a488b + 2258d03 commit e34b7bc

40 files changed

+6768
-4226
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.2.0-{build}
1+
version: 1.3.0-{build}
22

33
environment:
44
matrix:

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
## [1.3.0] - 2019-04-27
9+
### Added
10+
- Added support for "use" keyword in closures
11+
[phalcon/zephir#1848]https://github.com/phalcon/zephir/issues/1848
12+
[phalcon/zephir#888]https://github.com/phalcon/zephir/issues/888
13+
14+
### Fixed
15+
- Fixed unicode support in the source code
16+
[#62](https://github.com/phalcon/php-zephir-parser/issues/62),
17+
[#56](https://github.com/phalcon/php-zephir-parser/issues/56)
18+
- Fixed memory leaks on processing errors
819

920
## [1.2.0] - 2019-01-14
1021
### Added
@@ -113,8 +124,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
113124
### Added
114125
- Initial stable release
115126

116-
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.2.0...HEAD
117-
[1.2.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.1.2...v1.2.0
127+
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.0...HEAD
128+
[1.3.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.2.0...v1.3.0
129+
[1.2.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.1.4...v1.2.0
118130
[1.1.4]: https://github.com/phalcon/php-zephir-parser/compare/v1.1.3...v1.1.4
119131
[1.1.3]: https://github.com/phalcon/php-zephir-parser/compare/v1.1.2...v1.1.3
120132
[1.1.2]: https://github.com/phalcon/php-zephir-parser/compare/v1.1.1...v1.1.2

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ namespace Acme;
109109

110110
class Greeting
111111
{
112-
public static function say() -> void
112+
public static function sayHello() -> void
113113
{
114-
echo "hello world!";
114+
echo "Hello, World!";
115115
}
116116
}
117117
EOF;

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.0
1+
1.3.0

parser/base.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
552552
switch (scanner_status) {
553553
case XX_SCANNER_RETCODE_ERR:
554554
case XX_SCANNER_RETCODE_IMPOSSIBLE:
555-
if (error_msg && Z_TYPE_P(error_msg) == IS_NULL) {
555+
if (error_msg && Z_TYPE_P(error_msg) != IS_ARRAY) {
556556
error = emalloc(sizeof(char) * 1024);
557557
if (state->cursor) {
558558
snprintf(error, 1024, "Scanner error: %d %s", scanner_status, state->cursor);
@@ -584,7 +584,6 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
584584
status = FAILURE;
585585
if (parser_status->syntax_error && error_msg && Z_TYPE_P(error_msg) != IS_ARRAY) {
586586
array_init(error_msg);
587-
588587
add_assoc_string(error_msg, "type", "error");
589588
add_assoc_string(error_msg, "message", parser_status->syntax_error);
590589
add_assoc_string(error_msg, "file", state->active_file);
@@ -597,7 +596,7 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
597596
}
598597
else if (error_msg && Z_TYPE_P(error_msg) != IS_ARRAY) {
599598
assert(Z_TYPE(parser_status->ret) == IS_ARRAY);
600-
ZVAL_ZVAL(error_msg, &parser_status->ret, 1, 1);
599+
ZVAL_COPY_VALUE(error_msg, &parser_status->ret);
601600
}
602601
}
603602

parser/parser.c

Lines changed: 4527 additions & 4198 deletions
Large diffs are not rendered by default.

parser/parser.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ static void xx_ret_expr(zval *ret, const char *type, zval *left, zval *right, zv
147147
parser_add_int(ret, "char", state->active_char);
148148
}
149149

150+
static void xx_ret_closure(zval *ret, zval *left, zval *right, zval *use, xx_scanner_state *state)
151+
{
152+
array_init(ret);
153+
154+
parser_add_str(ret, "type", "closure");
155+
156+
if (left) {
157+
parser_add_zval(ret, "left", left);
158+
}
159+
160+
if (right) {
161+
parser_add_zval(ret, "right", right);
162+
}
163+
164+
if (use) {
165+
parser_add_zval(ret, "use", use);
166+
}
167+
168+
parser_add_str(ret, "file", state->active_file);
169+
parser_add_int(ret, "line", state->active_line);
170+
parser_add_int(ret, "char", state->active_char);
171+
}
172+
150173
static void xx_ret_array_item(zval *ret, zval *key, zval *value, xx_scanner_state *state)
151174
{
152175
array_init(ret);

parser/scanner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "scanner.h"
2121

2222
// for re2c
23-
#define YYCTYPE char
23+
#define YYCTYPE unsigned char
2424
#define YYCURSOR (s->cursor)
2525
#define YYLIMIT (s->limit)
2626
#define YYMARKER (s->marker)

parser/scanner.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "scanner.h"
1919

2020
// for re2c
21-
#define YYCTYPE char
21+
#define YYCTYPE unsigned char
2222
#define YYCURSOR (s->cursor)
2323
#define YYLIMIT (s->limit)
2424
#define YYMARKER (s->marker)

parser/zephir.lemon

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
2-
/*
1+
/* zephir.lemon
2+
*
33
* This file is part of the Zephir Parser.
44
*
55
* (c) Zephir Team <[email protected]>
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

@@ -71,6 +76,7 @@
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

8693
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
265272
xx_ret_class(&R, I, &B, 0, 1, E, &L, status->scanner_state);
266273
}
267274

275+
/* TODO: Add internall class */
276+
268277
xx_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 () { } */
20862095
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);
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() { ... } */
20912106
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);
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) { } */
20962116
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);
20982123
}
20992124

2100-
/** function(a, b, c) { ... }*/
2125+
/* function(a, b, c) { ... } */
21012126
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);
21032163
}
21042164

2105-
/** x => x + 1 */
2165+
/* x => x + 1 */
21062166
xx_common_expr(R) ::= IDENTIFIER(I) DOUBLEARROW xx_common_expr(E) . {
21072167
{
21082168
zval identifier;

tests/base/cblocks.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ZEP;
2929
$ir = zephir_parse_file($code, '(eval code)');
3030

3131
var_dump($ir);
32+
?>
3233
--EXPECT--
3334
array(2) {
3435
[0]=>

tests/base/types.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ZEP;
3737
$ir = zephir_parse_file($code, '(eval code)');
3838

3939
var_dump($ir);
40+
?>
4041
--EXPECT--
4142
array(2) {
4243
[0]=>

tests/base/variables.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ZEP;
2727
$ir = zephir_parse_file($code, '(eval code)');
2828

2929
var_dump($ir);
30+
?>
3031
--EXPECT--
3132
array(2) {
3233
[0]=>

tests/cf/while01.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ZEP;
1616
$ir = zephir_parse_file($code, '(eval code)');
1717

1818
var_dump($ir);
19+
?>
1920
--EXPECT--
2021
array(2) {
2122
[0]=>

tests/classes/bug48.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ZEP;
1818
$ir = zephir_parse_file($code, '(eval code)');
1919

2020
var_dump($ir);
21+
?>
2122
--EXPECT--
2223
array(3) {
2324
[0]=>

tests/comments/comment.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ZEP;
2020
$ir = zephir_parse_file($code, '(eval code)');
2121

2222
var_dump($ir);
23+
?>
2324
--EXPECT--
2425
array(2) {
2526
[0]=>

tests/comments/comments_before.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ZEP;
4040
var_dump(zephir_parse_file($code1, '(eval code)'));
4141
var_dump(zephir_parse_file($code2, '(eval code)'));
4242
var_dump(zephir_parse_file($code3, '(eval code)'));
43+
?>
4344
--EXPECT--
4445
array(2) {
4546
[0]=>

tests/comments/dockblocks/bug13.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ZEP;
2020
$ir = zephir_parse_file($code, '(eval code)');
2121

2222
echo $ir[1]["definition"]["properties"][0]["docblock"];
23+
?>
2324
--EXPECT--
2425
**
2526
* @var \stdClass

tests/comments/dockblocks/simple.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ZEP;
2020
$ir = zephir_parse_file($code, '(eval code)');
2121

2222
echo $ir[1]["value"];
23+
?>
2324
--EXPECT--
2425
**
2526
* DocBlockFail

tests/comments/sl_comment.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ZEP;
2020
$ir = zephir_parse_file($code, '(eval code)');
2121

2222
var_dump($ir);
23+
?>
2324
--EXPECT--
2425
array(2) {
2526
[0]=>

tests/errors/001.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Test
1818
ZEP;
1919

2020
var_dump(zephir_parse_file($code, '(eval code)'));
21+
?>
2122
--EXPECT--
2223
array(5) {
2324
["type"]=>

tests/errors/bug30.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Test
1717
ZEP;
1818

1919
var_dump(zephir_parse_file($code, '(eval code)'));
20+
?>
2021
--EXPECTF--
2122
array(5) {
2223
["type"]=>

0 commit comments

Comments
 (0)