Skip to content

Commit 8f899d2

Browse files
committed
Allow comments between intersection types and by-ref params
1 parent 21cab65 commit 8f899d2

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Intersection type parsing and by-ref parsing interaction with attributes
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public X& #[Comment]
8+
Z $p;
9+
}
10+
11+
?>
12+
--EXPECTF--
13+
Parse error: syntax error, unexpected token "#[" in %s on line %d
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Intersection type and by-ref parameter parsing with comments
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
function f1(A & /*
8+
Comment // ** / / * * **/ B $p) {}
9+
function f2(A & // Comment
10+
B $p) {}
11+
function f3(A & # Comment
12+
B $p) {}
13+
function f4(A & #
14+
B $p) {}
15+
function f6(A & /*
16+
Comment // ** / / * * **/ $p) {}
17+
function f7(A & // Comment
18+
$p) {}
19+
function f8(A & # Comment
20+
$p) {}
21+
function f9(A & #
22+
$p) {}
23+
}
24+
25+
?>
26+
--EXPECT--

Zend/zend_language_scanner.l

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,12 @@ TABS_AND_SPACES [ \t]*
13681368
TOKENS [;:,.|^&+-/*=%!~$<>?@]
13691369
ANY_CHAR [^]
13701370
NEWLINE ("\r"|"\n"|"\r\n")
1371+
OPTIONAL_WHITESPACE [ \n\r\t]*
1372+
MULTI_LINE_COMMENT "/*"([^*]*"*"+)([^*/][^*]*"*"+)*"/"
1373+
SINGLE_LINE_COMMENT "//".*[\n\r]
1374+
HASH_COMMENT "#"(([^[].*[\n\r])|[\n\r])
1375+
WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_COMMENT}|{HASH_COMMENT})+
1376+
OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_COMMENT}|{HASH_COMMENT})*
13711377

13721378
/* compute yyleng before each rule */
13731379
<!*> := yyleng = YYCURSOR - SCNG(yy_text);
@@ -1401,7 +1407,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
14011407
RETURN_TOKEN(T_ATTRIBUTE);
14021408
}
14031409

1404-
<ST_IN_SCRIPTING>"yield"{WHITESPACE}"from"[^a-zA-Z0-9_\x80-\xff] {
1410+
<ST_IN_SCRIPTING>"yield"{WHITESPACE_OR_COMMENTS}"from"[^a-zA-Z0-9_\x80-\xff] {
14051411
yyless(yyleng - 1);
14061412
HANDLE_NEWLINES(yytext, yyleng);
14071413
RETURN_TOKEN_WITH_IDENT(T_YIELD_FROM);
@@ -1543,11 +1549,11 @@ NEWLINE ("\r"|"\n"|"\r\n")
15431549
* The enum keyword must be followed by whitespace and another identifier.
15441550
* This avoids the BC break of using enum in classes, namespaces, functions and constants.
15451551
*/
1546-
<ST_IN_SCRIPTING>"enum"{WHITESPACE}("extends"|"implements") {
1552+
<ST_IN_SCRIPTING>"enum"{WHITESPACE_OR_COMMENTS}("extends"|"implements") {
15471553
yyless(4);
15481554
RETURN_TOKEN_WITH_STR(T_STRING, 0);
15491555
}
1550-
<ST_IN_SCRIPTING>"enum"{WHITESPACE}[a-zA-Z_\x80-\xff] {
1556+
<ST_IN_SCRIPTING>"enum"{WHITESPACE_OR_COMMENTS}[a-zA-Z_\x80-\xff] {
15511557
yyless(4);
15521558
RETURN_TOKEN_WITH_IDENT(T_ENUM);
15531559
}
@@ -1869,7 +1875,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
18691875
RETURN_TOKEN(T_SR);
18701876
}
18711877

1872-
<ST_IN_SCRIPTING>"&"[ \t\r\n]*("$"|"...") {
1878+
<ST_IN_SCRIPTING>"&"{OPTIONAL_WHITESPACE_OR_COMMENTS}("$"|"...") {
18731879
yyless(1);
18741880
RETURN_TOKEN(T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG);
18751881
}

0 commit comments

Comments
 (0)