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

CFamily: Lex identifiers after case as constants #2084

Merged
merged 5 commits into from
Mar 12, 2022

Conversation

amitkummer
Copy link
Contributor

Add a state for marking identifiers preceded by a case keyword as constants.

Additionally, refactor the label rule to no longer permit a case keyword before a label.

Consequentially, identifiers after a case keyword (like foo in case foo:) are no longer wrongly lexed as Name.Label, but as
Name.Constant.

In addition, this fixes #2076, as multiple case keywords in one line are lexed the same.

Add a state for marking identifiers preceded by  a `case` keyword as
constants.

Additionally, refactor the `label` rule to no longer permit a `case`
keyword before a label.

Consequentially, identifiers after a `case` keyword (like `foo` in
`case foo:`) are no longer wrongly lexed as `Name.Label`, but as
`Name.Constant`.

In addition, this fixes pygments#2076, as multiple `case` keywords in one
line are lexed the same.
pygments/lexers/c_cpp.py Outdated Show resolved Hide resolved
@jeanas
Copy link
Contributor

jeanas commented Mar 9, 2022

I'll leave this for a few days in case other maintainers would like to take a look.

After a `case`, when lexing a namespaced name, like `foo::bar`, lex the
namespace operator `::` as Operator, and not Name.Constant.
@amitkummer
Copy link
Contributor Author

I made a small oversight, so I pushed a couple of commits with a fix. I am sorry for the inconvenience, but I think it should be all good now.

Instead of lexing foo::bar, as Name.Constant, it's now lexed as:

foo  Name.Constant
:    Operator
:    Operator
bar  Name.Constant

Which is more correct and also consistent with how the lexer treats the :: operator.

@Anteru
Copy link
Collaborator

Anteru commented Mar 12, 2022

This looks good to me. Thanks for working on this!

@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Mar 12, 2022
@Anteru Anteru added this to the 2.12.0 milestone Mar 12, 2022
@Anteru Anteru merged commit 62dd19e into pygments:master Mar 12, 2022
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label Mar 27, 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.

case value not highlighting in C++
3 participants