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

Improve consistency of lexing of class-like names in C++ lexer #1495

Merged
merged 4 commits into from Apr 12, 2020

Conversation

pyrmont
Copy link
Contributor

@pyrmont pyrmont commented Apr 10, 2020

Rouge's C++ lexer currently tokenises identifiers that come after the class keyword with the Name::Class token and identifiers that come after the struct keyword with the generic Name token. This is despite the fact that the only difference between a struct and a class in C++ is the default access specifier. Similarly, when used in a template definition, a typename is equivalent to a class but Rouge treats the identifiers that follow the typename and class keywords differently.

This PR addresses this problem. It treats class and struct as equivalent in all cases while treating typename as equivalent when used in a template definition.

It fixes #1484.

@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Apr 10, 2020
@pyrmont pyrmont self-assigned this Apr 10, 2020
@pyrmont
Copy link
Contributor Author

pyrmont commented Apr 10, 2020

There are are a number of issues mentioned in #394, but for ease of reference, I note that this will fix two of the bullet points in the OP.

@pyrmont
Copy link
Contributor Author

pyrmont commented Apr 10, 2020

@integricho Sorry to lean on you again but if you're able to have a peek at this, that'd be great. I don't think I'll ever not feel out of my depth when it comes to C++ :P

lib/rouge/lexers/cpp.rb Outdated Show resolved Hide resolved
@n0phx
Copy link

n0phx commented Apr 10, 2020

Looks good, thanks! but take everything I say with a grain of salt :)

@pyrmont pyrmont merged commit 3fafcfa into rouge-ruby:master Apr 12, 2020
@pyrmont pyrmont deleted the bugfix.cpp-class-like-symbols branch April 12, 2020 07:08
@pyrmont pyrmont removed the needs-review The PR needs to be reviewed label Apr 12, 2020
@pyrmont
Copy link
Contributor Author

pyrmont commented Apr 12, 2020

@integricho Thanks for your help! I've merged this into the main branch and it will be part of the next release of Rouge. That's scheduled for release on Tuesday 14 April 🎉

mattt pushed a commit to NSHipster/rouge that referenced this pull request May 21, 2020
…ouge-ruby#1495)

Rouge's C++ lexer currently tokenises identifiers that come after the
class keyword with the `Name::Class` token and identifiers that come
after the `struct` keyword with the generic `Name` token. This is
despite the fact that the only difference between a struct and a class
in C++ is the default access specifier. Similarly, when used in a
template definition, a typename is equivalent to a class but Rouge 
treats the identifiers that follow the `typename` and `class` keywords 
differently.

This commit addresses this problem. It treats class and struct as
equivalent in all cases while treating typename as equivalent when used
in a template definition.
pyrmont added a commit that referenced this pull request Jul 4, 2020
The change in #1495 to the way that the `template` keyword caused
template parameter packs not to be highlighted correctly. This commit
fixes that bug while also introducing a more robust set of rules for
highlighting identifiers succeeding the `template` keyword.
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
The change in rouge-ruby#1495 to the way that the `template` keyword caused
template parameter packs not to be highlighted correctly. This commit
fixes that bug while also introducing a more robust set of rules for
highlighting identifiers succeeding the `template` keyword.
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.

Structs, classes and typenames should be lexed similarly in C++ lexer
2 participants