Skip to content

Commit 54abed8

Browse files
committed
Allow comments between intersection types and by-ref params
1 parent b96b88b commit 54abed8

File tree

3 files changed

+43
-1
lines changed

3 files changed

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

Zend/zend_language_scanner.l

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,11 @@ 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+
OPTIONAL_WHITESPACE_AND_COMMENTS ({OPTIONAL_WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_COMMENT}|{HASH_COMMENT})*
13711376

13721377
/* compute yyleng before each rule */
13731378
<!*> := yyleng = YYCURSOR - SCNG(yy_text);
@@ -1869,7 +1874,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
18691874
RETURN_TOKEN(T_SR);
18701875
}
18711876

1872-
<ST_IN_SCRIPTING>"&"[ \t\r\n]*("$"|"...") {
1877+
<ST_IN_SCRIPTING>"&"{OPTIONAL_WHITESPACE_AND_COMMENTS}("$"|"...") {
18731878
yyless(1);
18741879
RETURN_TOKEN(T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG);
18751880
}

0 commit comments

Comments
 (0)