-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Treat namespaced names as single token (reduced version) #5827
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Cannot use "namespace" as namespace name, due to conflict with ns-relative names | ||
--FILE-- | ||
<?php | ||
|
||
namespace NAMEspace; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot use 'NAMEspace' as namespace name in %s on line %d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Cannot use "namespace\xyz" as namespace name, due to conflict with ns-relative names | ||
--FILE-- | ||
<?php | ||
|
||
namespace NAMEspace\xyz; | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected namespace-relative name "NAMEspace\xyz", expecting "{" in %s on line %d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
Reserved keywords in namespace name | ||
--FILE-- | ||
<?php | ||
|
||
namespace iter\fn { | ||
function test() { | ||
echo __FUNCTION__, "\n"; | ||
} | ||
} | ||
|
||
namespace fn { | ||
function test() { | ||
echo __FUNCTION__, "\n"; | ||
} | ||
} | ||
|
||
namespace self { | ||
function test() { | ||
echo __FUNCTION__, "\n"; | ||
} | ||
} | ||
|
||
namespace { | ||
use iter\fn; | ||
use function fn\test as test2; | ||
use function self\test as test3; | ||
fn\test(); | ||
test2(); | ||
test3(); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
iter\fn\test | ||
fn\test | ||
self\test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Whitespace between namespace separators is no longer allowed | ||
--FILE-- | ||
<?php | ||
|
||
Foo \ Bar \ Baz; | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "\" in %s on line %d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--TEST-- | ||
Tokenization of namespaced names | ||
--FILE-- | ||
<?php | ||
|
||
$code = <<<'CODE' | ||
<?php | ||
Foo | ||
Foo\Bar | ||
\Foo\Bar | ||
namespace\Foo | ||
Foo \ Bar | ||
CODE; | ||
|
||
foreach (PhpToken::getAll($code) as $token) { | ||
echo "{$token->getTokenName()}: \"$token->text\"\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
T_OPEN_TAG: "<?php | ||
" | ||
T_STRING: "Foo" | ||
T_WHITESPACE: " | ||
" | ||
T_NAME_QUALIFIED: "Foo\Bar" | ||
T_WHITESPACE: " | ||
" | ||
T_NAME_FULLY_QUALIFIED: "\Foo\Bar" | ||
T_WHITESPACE: " | ||
" | ||
T_NAME_RELATIVE: "namespace\Foo" | ||
T_WHITESPACE: " | ||
" | ||
T_STRING: "Foo" | ||
T_WHITESPACE: " " | ||
T_NS_SEPARATOR: "\" | ||
T_WHITESPACE: " " | ||
T_STRING: "Bar" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor oversight in the implementation that should be easy to address (It's easy to forget about. I assume the author will address this, and supporting tokens would generally be assumed to be part of the final implementation of any RFC adding a new token type, for anyone wondering. I've made this mistake in drafts of other unrelated RFC implementations I've worked on):
char *get_token_type_name
should be updated with the new token types, so that calls from PHP to token_name() (and possibly error messages)At least 2 parts of ext/tokenizer/tokenizer_data.c need to be updated
Currently (the exact value may be different, I also merged another RFC implementation for this php build),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I had indeed forgotten about this. Should be fixed now!