Skip to content

PHP: 8.x keywords #2054

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

Merged
merged 1 commit into from
Jan 31, 2022
Merged

PHP: 8.x keywords #2054

merged 1 commit into from
Jan 31, 2022

Conversation

ancarda
Copy link
Contributor

@ancarda ancarda commented Jan 28, 2022

This is part of the work required to get PHP 8.x support in Pygments. There is something else that needs to be added onto this patch that I couldn't figure out.

The file pygments/lexers/_php_builtins.py needs to be regenerated as there are several new functions in the standard library, such as str_starts_with (8.0) and array_is_list (8.1). I tried to run it locally after installing requirements.txt with Pip, but I keep getting ModuleNotFoundError. I'm not a Python developer, what do I need to do to get this to rebuild?

@ancarda ancarda changed the title php: Add readonly (8.1) and match (8.0) keywords WIP: PHP 8.x support Jan 28, 2022
@birkenfeld
Copy link
Member

A full error message would be helpful. Which module raises ModuleNotFoundError?

@ancarda
Copy link
Contributor Author

ancarda commented Jan 28, 2022

Sorry, that was awful of me for not including the error message.

I'm trying to execute the file directly. I don't know if this is the right thing to do or not.

% python3 --version
Python 3.8.8

% pip3 --version
pip 21.0.1 from /opt/anaconda3/lib/python3.8/site-packages/pip (python 3.8)

% pip3 install -r requirements.txt 
Requirement already satisfied: pytest-cov in /opt/anaconda3/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (3.0.0)
Requirement already satisfied: pytest-randomly in /opt/anaconda3/lib/python3.8/site-packages (from -r requirements.txt (line 2)) (3.11.0)
Requirement already satisfied: pytest>=6.0 in /opt/anaconda3/lib/python3.8/site-packages (from -r requirements.txt (line 3)) (6.2.3)
[...omitted...]

% python3 pygments/lexers/_php_builtins.py
Traceback (most recent call last):
  File "pygments/lexers/_php_builtins.py", line 4683, in <module>
    from urllib.request import urlretrieve
  File "/opt/anaconda3/lib/python3.8/urllib/request.py", line 88, in <module>
    import http.client
  File "/opt/anaconda3/lib/python3.8/http/client.py", line 71, in <module>
    import email.parser
ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package

@birkenfeld
Copy link
Member

birkenfeld commented Jan 29, 2022

Oh right, this is due to the pygments/lexers/email.py being imported instead of the standard module. You can run the script with python3 -I to avoid having the path of the script in the search path.

@birkenfeld
Copy link
Member

OK, since there were a few more snags, I've updated the file in #2056 - can you check if it matches what you'd expect?

@ancarda ancarda changed the title WIP: PHP 8.x support PHP: 8.x keywords Jan 29, 2022
@ancarda ancarda marked this pull request as ready for review January 29, 2022 12:06
@@ -221,7 +221,7 @@ class PhpLexer(RegexLexer):
r'array|E_ALL|NULL|final|php_user_filter|interface|'
r'implements|public|private|protected|abstract|clone|try|'
r'catch|throw|this|use|namespace|trait|yield|'
r'finally)\b', Keyword),
r'finally|match)\b', Keyword),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure readonly is in the right place, however there's two places where switch is defined (Keyword and Keyword.Declaration). Is there a way I can test this to make sure it works? Match works just like switch:

switch ($var) {
  case 'a':
    $result = "some value";
    break;
  case 'b':
    $result = "some other value";
    break;
}

// can be replaced with

$result = match ($var) {
  'a' => "some value",
  'b' => "some other value",
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the other place? In any case, this LGTM.

@birkenfeld birkenfeld merged commit ed3f436 into pygments:master Jan 31, 2022
@ancarda ancarda deleted the php8x-support branch February 2, 2022 07:06
@birkenfeld birkenfeld added the changelog-update Items which need to get mentioned in the changelog label Feb 8, 2022
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label Feb 20, 2022
@Anteru Anteru added this to the 2.12.0 milestone Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants