Skip to content

Commit 70eee9e

Browse files
authored
Merge pull request #124 from zephir-lang/development
1.4.0
2 parents 4517f3b + e529246 commit 70eee9e

21 files changed

+1532
-8
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88

9+
## [1.4.0] - 2021-09-18
10+
### Added
11+
- Added support for `mixed` type [#120](https://github.com/phalcon/php-zephir-parser/issues/120)
12+
- Added support for `yield` statement [#118](https://github.com/phalcon/php-zephir-parser/issues/118)
13+
914
## [1.3.8] - 2021-09-08
1015
### Changed
1116
- Changed CI from AppVeyor to Github Actions [#110](https://github.com/phalcon/php-zephir-parser/issues/110)
@@ -168,7 +173,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
168173
### Added
169174
- Initial stable release
170175

171-
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.8...HEAD
176+
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.0...HEAD
177+
[1.4.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.8...v1.4.0
172178
[1.3.8]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.7...v1.3.8
173179
[1.3.7]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.6...v1.3.7
174180
[1.3.6]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.5...v1.3.6

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
MIT License
33

4-
Copyright (c) 2013-2019 Zephir Team
4+
Copyright (c) 2013-present Zephir Team
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.8
1+
1.4.0

config.m4

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ if test "$PHP_ZEPHIR_PARSER" = "yes"; then
6868
[PHP_INSTALL_HEADERS([ext/zephir_parser], $PHP_ZEPHIR_PARSER_HEADERS)])
6969

7070
PHP_ADD_MAKEFILE_FRAGMENT([parser.mk])
71+
72+
dnl Create directories because PECL can't
73+
if test ! -d parser; then
74+
mkdir parser
75+
fi
7176
fi
7277

7378
dnl Code Coverage -------------------------------------------------------------

package.xml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package packagerversion="1.10.5" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
3+
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
5+
<name>zephir_parser</name>
6+
<channel>pecl.php.net</channel>
7+
<summary>Zephir code parser.</summary>
8+
<description>Zephir Parser is a code parser, delivered as a C extension for the PHP language.</description>
9+
<lead>
10+
<name>Anton Vasiliev</name>
11+
<user>jeckerson</user>
12+
<email>[email protected]</email>
13+
<active>yes</active>
14+
</lead>
15+
<date>2021-09-18</date>
16+
<time>11:00:00</time>
17+
<version>
18+
<release>1.4.0</release>
19+
<api>1.4.0</api>
20+
</version>
21+
<stability>
22+
<release>stable</release>
23+
<api>stable</api>
24+
</stability>
25+
<license uri="https://github.com/zephir-lang/php-zephir-parser/blob/development/LICENSE">MIT</license>
26+
<notes>
27+
Sat, Sep 18, 2021 - Zephir Parser 1.4.0
28+
29+
= New features:
30+
31+
- Fixed issue #120: Add support for `mixed` type
32+
- Fixed issue #118: Add support for `yield` statement
33+
</notes>
34+
<contents>
35+
<dir name="/">
36+
<dir name="parser">
37+
<file name="parser.c" role="src"/>
38+
<file name="scanner.c" role="src"/>
39+
40+
<file name="parser.h" role="src"/>
41+
<file name="scanner.h" role="src"/>
42+
<file name="xx.h" role="src"/>
43+
<file name="zephir.h" role="src"/>
44+
</dir>
45+
46+
<file name="config.m4" role="src"/>
47+
<file name="config.w32" role="src"/>
48+
<file name="zephir_parser.c" role="src"/>
49+
<file name="zephir_parser.h" role="src"/>
50+
<file name="CHANGELOG.md" role="doc"/>
51+
<file name="CODE_OF_CONDUCT.md" role="doc"/>
52+
<file name="LICENSE" role="doc"/>
53+
<file name="NO_WARRANTY" role="doc"/>
54+
</dir>
55+
</contents>
56+
<dependencies>
57+
<required>
58+
<php>
59+
<min>7.0.0</min>
60+
<max>8.0.99</max>
61+
</php>
62+
<pearinstaller>
63+
<min>1.10</min>
64+
</pearinstaller>
65+
</required>
66+
</dependencies>
67+
<providesextension>zephir_parser</providesextension>
68+
<extsrcrelease/>
69+
</package>

parser/base.c

+6
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
178178
case XX_T_RETURN:
179179
xx_(xx_parser, XX_RETURN, NULL, parser_status);
180180
break;
181+
case XX_T_YIELD:
182+
xx_(xx_parser, XX_YIELD, NULL, parser_status);
183+
break;
181184
case XX_T_REQUIRE_ONCE:
182185
xx_(xx_parser, XX_REQUIRE_ONCE, NULL, parser_status);
183186
break;
@@ -444,6 +447,9 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
444447
case XX_T_TYPE_RESOURCE:
445448
xx_(xx_parser, XX_TYPE_RESOURCE, NULL, parser_status);
446449
break;
450+
case XX_T_TYPE_MIXED:
451+
xx_(xx_parser, XX_TYPE_MIXED, NULL, parser_status);
452+
break;
447453
case XX_T_TYPE_CALLABLE:
448454
xx_(xx_parser, XX_TYPE_CALLABLE, NULL, parser_status);
449455
break;

parser/parser.h

+30-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ static void xx_ret_return_type_item(zval *ret, zval *type, zval *cast, int manda
534534
static void xx_ret_type(zval *ret, int type)
535535
{
536536
switch (type) {
537-
538537
case XX_TYPE_INTEGER:
539538
parser_get_string(ret, "int");
540539
return;
@@ -587,6 +586,10 @@ static void xx_ret_type(zval *ret, int type)
587586
parser_get_string(ret, "object");
588587
return;
589588

589+
case XX_TYPE_MIXED:
590+
parser_get_string(ret, "mixed");
591+
return;
592+
590593
case XX_T_TYPE_NULL:
591594
parser_get_string(ret, "null");
592595
return;
@@ -896,6 +899,28 @@ static void xx_ret_return_statement(zval *ret, zval *expr, xx_scanner_state *sta
896899
parser_add_int(ret, "char", state->active_char);
897900
}
898901

902+
static void xx_ret_yield_statement(zval *ret, zval *expr, zval *K, zval *V, xx_scanner_state *state)
903+
{
904+
array_init(ret);
905+
906+
parser_add_str(ret, "type", "yield");
907+
if (expr) {
908+
parser_add_zval(ret, "expr", expr);
909+
}
910+
911+
if (K) {
912+
parser_add_zval(ret, "key", K);
913+
}
914+
915+
if (V) {
916+
parser_add_zval(ret, "value", V);
917+
}
918+
919+
parser_add_str(ret, "file", state->active_file);
920+
parser_add_int(ret, "line", state->active_line);
921+
parser_add_int(ret, "char", state->active_char);
922+
}
923+
899924
static void xx_ret_require_once_statement(zval *ret, zval *expr, xx_scanner_state *state)
900925
{
901926
array_init(ret);
@@ -1040,6 +1065,10 @@ static void xx_ret_declare_statement(zval *ret, int type, zval *variables, xx_sc
10401065
parser_add_str(ret, "data-type", "resource");
10411066
break;
10421067

1068+
case XX_T_TYPE_MIXED:
1069+
parser_add_str(ret, "data-type", "mixed");
1070+
break;
1071+
10431072
case XX_T_TYPE_OBJECT:
10441073
parser_add_str(ret, "data-type", "object");
10451074
break;

parser/scanner.h

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define XX_T_TYPE_RESOURCE 333
4747
#define XX_T_TYPE_NULL 334
4848
#define XX_T_TYPE_THIS 335
49+
#define XX_T_TYPE_MIXED 336
4950

5051
#define XX_T_NAMESPACE 350
5152
#define XX_T_CLASS 351
@@ -98,6 +99,7 @@
9899
#define XX_T_CATCH 398
99100
#define XX_T_DEPRECATED 399
100101
#define XX_T_REQUIRE_ONCE 459
102+
#define XX_T_YIELD 460
101103

102104
/* Operators */
103105
#define XX_T_AT '@'

parser/scanner.re

+12
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ int xx_get_token(xx_scanner_state *s, xx_scanner_token *token) {
297297
return 0;
298298
}
299299
300+
'mixed' {
301+
s->active_char += sizeof("mixed")-1;
302+
token->opcode = XX_T_TYPE_MIXED;
303+
return 0;
304+
}
305+
300306
'if' {
301307
s->active_char += sizeof("if")-1;
302308
token->opcode = XX_T_IF;
@@ -357,6 +363,12 @@ int xx_get_token(xx_scanner_state *s, xx_scanner_token *token) {
357363
return 0;
358364
}
359365
366+
'yield' {
367+
s->active_char += sizeof("yield")-1;
368+
token->opcode = XX_T_YIELD;
369+
return 0;
370+
}
371+
360372
'require' {
361373
s->active_char += sizeof("require")-1;
362374
token->opcode = XX_T_REQUIRE;

parser/zephir.lemon

+30-3
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,10 @@ xx_parameter_type(R) ::= TYPE_RESOURCE . {
946946
xx_ret_type(&R, XX_TYPE_RESOURCE);
947947
}
948948

949+
xx_parameter_type(R) ::= TYPE_MIXED . {
950+
xx_ret_type(&R, XX_TYPE_MIXED);
951+
}
952+
949953
xx_parameter_type(R) ::= TYPE_OBJECT . {
950954
xx_ret_type(&R, XX_TYPE_OBJECT);
951955
}
@@ -982,6 +986,10 @@ xx_statement(R) ::= xx_return_statement(S) . {
982986
R = S;
983987
}
984988

989+
xx_statement(R) ::= xx_yield_statement(S) . {
990+
R = S;
991+
}
992+
985993
xx_statement(R) ::= xx_require_once_statement(S) . {
986994
R = S;
987995
}
@@ -1522,16 +1530,31 @@ xx_fetch_statement(R) ::= xx_fetch_expr(E) DOTCOMMA . {
15221530
xx_ret_fetch_statement(&R, &E, status->scanner_state);
15231531
}
15241532

1525-
/* return statement */
1533+
/* return var; */
15261534
xx_return_statement(R) ::= RETURN xx_common_expr(E) DOTCOMMA . {
15271535
xx_ret_return_statement(&R, &E, status->scanner_state);
15281536
}
15291537

1530-
/* return statement */
1538+
/* return; */
15311539
xx_return_statement(R) ::= RETURN DOTCOMMA . {
15321540
xx_ret_return_statement(&R, NULL, status->scanner_state);
15331541
}
15341542

1543+
/* yield var; */
1544+
xx_yield_statement(R) ::= YIELD xx_common_expr(E) DOTCOMMA . {
1545+
xx_ret_yield_statement(&R, &E, NULL, NULL, status->scanner_state);
1546+
}
1547+
1548+
/* yield key, val; */
1549+
xx_yield_statement(R) ::= YIELD xx_common_expr(K) COMMA xx_common_expr(V) DOTCOMMA . {
1550+
xx_ret_yield_statement(&R, NULL, &K, &V, status->scanner_state);
1551+
}
1552+
1553+
/* yield; */
1554+
xx_yield_statement(R) ::= YIELD DOTCOMMA . {
1555+
xx_ret_yield_statement(&R, NULL, NULL, NULL, status->scanner_state);
1556+
}
1557+
15351558
/* require_once statement */
15361559
xx_require_once_statement(R) ::= REQUIRE_ONCE xx_common_expr(E) DOTCOMMA . {
15371560
xx_ret_require_once_statement(&R, &E, status->scanner_state);
@@ -1596,6 +1619,10 @@ xx_declare_statement(R) ::= TYPE_ARRAY xx_declare_variable_list(L) DOTCOMMA . {
15961619
xx_ret_declare_statement(&R, XX_T_TYPE_ARRAY, &L, status->scanner_state);
15971620
}
15981621

1622+
xx_declare_statement(R) ::= TYPE_MIXED xx_declare_variable_list(L) DOTCOMMA . {
1623+
xx_ret_declare_statement(&R, XX_T_TYPE_MIXED, &L, status->scanner_state);
1624+
}
1625+
15991626
xx_declare_variable_list(R) ::= xx_declare_variable_list(L) COMMA xx_declare_variable(V) . {
16001627
xx_ret_list(&R, &L, &V, status->scanner_state);
16011628
}
@@ -1898,7 +1925,7 @@ xx_common_expr(R) ::= NULL . {
18981925
xx_ret_literal(&R, XX_T_NULL, NULL, status->scanner_state);
18991926
}
19001927

1901-
/* y = false */
1928+
/* y = true */
19021929
xx_common_expr(R) ::= TRUE . {
19031930
xx_ret_literal(&R, XX_T_TRUE, NULL, status->scanner_state);
19041931
}
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
Parameter type 'int'
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$code =<<<ZEP
8+
function test(int value) { }
9+
ZEP;
10+
11+
$ir = zephir_parse_file($code, '(eval code)');
12+
var_dump($ir);
13+
?>
14+
--EXPECT--
15+
array(1) {
16+
[0]=>
17+
array(6) {
18+
["type"]=>
19+
string(8) "function"
20+
["name"]=>
21+
string(4) "test"
22+
["parameters"]=>
23+
array(1) {
24+
[0]=>
25+
array(9) {
26+
["type"]=>
27+
string(9) "parameter"
28+
["name"]=>
29+
string(5) "value"
30+
["const"]=>
31+
int(0)
32+
["data-type"]=>
33+
string(3) "int"
34+
["mandatory"]=>
35+
int(0)
36+
["reference"]=>
37+
int(0)
38+
["file"]=>
39+
string(11) "(eval code)"
40+
["line"]=>
41+
int(1)
42+
["char"]=>
43+
int(25)
44+
}
45+
}
46+
["file"]=>
47+
string(11) "(eval code)"
48+
["line"]=>
49+
int(1)
50+
["char"]=>
51+
int(9)
52+
}
53+
}

0 commit comments

Comments
 (0)