Skip to content

Commit

Permalink
Switch from _ to * for wildcard pattern
Browse files Browse the repository at this point in the history
This avoids a BC break, and/or incompatibilities with _ named types.
  • Loading branch information
iluuu1994 committed Jun 19, 2024
1 parent fc205f6 commit 16fdc6b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 46 deletions.
19 changes: 0 additions & 19 deletions Zend/tests/pattern_matching/is/underscore_bc.phpt

This file was deleted.

14 changes: 7 additions & 7 deletions Zend/tests/pattern_matching/is/wildcard.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Wildcard pattern matching

class Foo {}

var_dump('' is _);
var_dump(42 is _);
var_dump(3.141 is _);
var_dump(null is _);
var_dump(true is _);
var_dump(new Foo() is _);
var_dump([1, 2, 3] is _);
var_dump('' is *);
var_dump(42 is *);
var_dump(3.141 is *);
var_dump(null is *);
var_dump(true is *);
var_dump(new Foo() is *);
var_dump([1, 2, 3] is *);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/pattern_matching/match/basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var_dump(match ('Foo') {
is 1 => wrong(),
is 2 => wrong(),
is 3 => wrong(),
is _ => 'Wildcard pattern',
is * => 'Wildcard pattern',
});

var_dump(match (15) {
Expand Down
5 changes: 2 additions & 3 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%token <ident> T_DEFAULT "'default'"
%token <ident> T_MATCH "'match'"
%token <ident> T_IS "'is'"
%token <ident> T_UNDERSCORE "'_'"
%token <ident> T_BREAK "'break'"
%token <ident> T_CONTINUE "'continue'"
%token <ident> T_GOTO "'goto'"
Expand Down Expand Up @@ -312,7 +311,7 @@ reserved_non_modifiers:
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT | T_BREAK
| T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_FN | T_MATCH | T_ENUM
| T_UNDERSCORE | T_IS
| T_IS
;

semi_reserved:
Expand Down Expand Up @@ -1298,7 +1297,7 @@ atomic_pattern:
| array_pattern { $$ = $1; }
| binding_pattern { $$ = $1; }
| class_const_pattern { $$ = $1; }
| T_UNDERSCORE { $$ = zend_ast_create(ZEND_AST_WILDCARD_PATTERN); }
| '*' { $$ = zend_ast_create(ZEND_AST_WILDCARD_PATTERN); }
| '(' pattern ')' {
$$ = $2;
if ($$->kind == ZEND_AST_OR_PATTERN || $$->kind == ZEND_AST_AND_PATTERN) {
Expand Down
8 changes: 0 additions & 8 deletions Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1509,14 +1509,6 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
RETURN_TOKEN_WITH_IDENT(T_IS);
}

<ST_IN_SCRIPTING>"_"[ \t\r\n]*"(" {
yyless(1);
RETURN_TOKEN_WITH_STR(T_STRING, 0);
}
<ST_IN_SCRIPTING>"_" {
RETURN_TOKEN_WITH_IDENT(T_UNDERSCORE);
}

<ST_IN_SCRIPTING>"endswitch" {
RETURN_TOKEN_WITH_IDENT(T_ENDSWITCH);
}
Expand Down
1 change: 0 additions & 1 deletion ext/tokenizer/tokenizer_data.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions ext/tokenizer/tokenizer_data.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@
* @cvalue T_IS
*/
const T_IS = UNKNOWN;
/**
* @var int
* @cvalue T_UNDERSCORE
*/
const T_UNDERSCORE = UNKNOWN;
/**
* @var int
* @cvalue T_BREAK
Expand Down
3 changes: 1 addition & 2 deletions ext/tokenizer/tokenizer_data_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16fdc6b

Please sign in to comment.