Skip to content

CFamily: Lex identifiers after case as constants#2084

Merged
Anteru merged 5 commits intopygments:masterfrom
amitkummer:c-label
Mar 12, 2022
Merged

CFamily: Lex identifiers after case as constants#2084
Anteru merged 5 commits intopygments:masterfrom
amitkummer:c-label

Conversation

@amitkummer
Copy link
Copy Markdown
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.
@jeanas
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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