Skip to content
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

Java: fix lexing of 'record' soft keyword #2018

Merged
merged 3 commits into from Jan 3, 2022

Conversation

amitkummer
Copy link
Contributor

@amitkummer amitkummer commented Jan 3, 2022

Refactor the Java lexer to treat record as a soft keyword. Fixes #2016.

Previously, the lexer assumed record is a reserved word, even though
it is a soft keyword which can be used as a variable name. This meant
that if pygments tried to highlight Java code like int record = 1
(assignment to a variable named record) an error token would be produced.

This refactor lexes record as a keyword only if it appears at the
beginning of the line, with some potential other keywords like public
and private preceding it.
I am not a Java expert at all, but after reading the JEP for records, I think this
covers all cases.

Refactor the Java lexer to treat `record` as a soft keyword.

Previously, the lexer assumed record is a reserved word, even though
it is a soft keyword which can be used as a variable name.

This refactor lexes record as a keyword only if it appears at the
beggining of the line, with some potential other keywords like public
and private preceding it.
@Anteru
Copy link
Collaborator

Anteru commented Jan 3, 2022

Thanks a lot for looking into this at such short notice! I think we'll get a 2.11.2 release out with that soon. Could you please check the lint issue though so I can merge this?

@Anteru Anteru added the A-lexing area: changes to individual lexers label Jan 3, 2022
@amitkummer
Copy link
Contributor Author

amitkummer commented Jan 3, 2022

Lint issue fixed.

Edit: well now the tests are failing.

@amitkummer
Copy link
Contributor Author

Should be all good now :)

@Anteru Anteru merged commit e0f4e77 into pygments:master Jan 3, 2022
@Anteru
Copy link
Collaborator

Anteru commented Jan 3, 2022

Perfect, merged as well. Thanks again for looking at this!

@amitkummer amitkummer deleted the java-record branch January 3, 2022 19:30
@Anteru Anteru added this to the 2.11.2 milestone Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lexing area: changes to individual lexers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error trying to highlight Java code with a "record" local variable
2 participants