Skip to content

Allow comments between intersection types and by-ref params #10125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Intersection type parsing and by-ref parsing interaction with attributes
--FILE--
<?php

class Test {
public X& #[Comment]
Z $p;
}

?>
--EXPECTF--
Parse error: syntax error, unexpected token "#[" in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Intersection type and by-ref parameter parsing with comments
--FILE--
<?php

class Test {
function f1(A & /*
Comment // ** / / * * **/ B $p) {}
function f2(A & // Comment
B $p) {}
function f3(A & # Comment
B $p) {}
function f4(A & #
B $p) {}
function f6(A & /*
Comment // ** / / * * **/ $p) {}
function f7(A & // Comment
$p) {}
function f8(A & # Comment
$p) {}
function f9(A & #
$p) {}
}

?>
--EXPECT--
14 changes: 10 additions & 4 deletions Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,12 @@ TABS_AND_SPACES [ \t]*
TOKENS [;:,.|^&+-/*=%!~$<>?@]
ANY_CHAR [^]
NEWLINE ("\r"|"\n"|"\r\n")
OPTIONAL_WHITESPACE [ \n\r\t]*
MULTI_LINE_COMMENT "/*"([^*]*"*"+)([^*/][^*]*"*"+)*"/"
SINGLE_LINE_COMMENT "//".*[\n\r]
HASH_COMMENT "#"(([^[].*[\n\r])|[\n\r])
WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_COMMENT}|{HASH_COMMENT})+
OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_COMMENT}|{HASH_COMMENT})*

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

<ST_IN_SCRIPTING>"yield"{WHITESPACE}"from"[^a-zA-Z0-9_\x80-\xff] {
<ST_IN_SCRIPTING>"yield"{WHITESPACE_OR_COMMENTS}"from"[^a-zA-Z0-9_\x80-\xff] {
yyless(yyleng - 1);
HANDLE_NEWLINES(yytext, yyleng);
RETURN_TOKEN_WITH_IDENT(T_YIELD_FROM);
Expand Down Expand Up @@ -1543,11 +1549,11 @@ NEWLINE ("\r"|"\n"|"\r\n")
* The enum keyword must be followed by whitespace and another identifier.
* This avoids the BC break of using enum in classes, namespaces, functions and constants.
*/
<ST_IN_SCRIPTING>"enum"{WHITESPACE}("extends"|"implements") {
<ST_IN_SCRIPTING>"enum"{WHITESPACE_OR_COMMENTS}("extends"|"implements") {
yyless(4);
RETURN_TOKEN_WITH_STR(T_STRING, 0);
}
<ST_IN_SCRIPTING>"enum"{WHITESPACE}[a-zA-Z_\x80-\xff] {
<ST_IN_SCRIPTING>"enum"{WHITESPACE_OR_COMMENTS}[a-zA-Z_\x80-\xff] {
yyless(4);
RETURN_TOKEN_WITH_IDENT(T_ENUM);
}
Expand Down Expand Up @@ -1869,7 +1875,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
RETURN_TOKEN(T_SR);
}

<ST_IN_SCRIPTING>"&"[ \t\r\n]*("$"|"...") {
<ST_IN_SCRIPTING>"&"{OPTIONAL_WHITESPACE_OR_COMMENTS}("$"|"...") {
yyless(1);
RETURN_TOKEN(T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG);
}
Expand Down