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

fix(cpp) fix class/template parsing issues #2752

Merged
merged 8 commits into from Oct 15, 2020

Conversation

joshgoebel
Copy link
Member

@joshgoebel joshgoebel commented Oct 15, 2020

This fixes #2716 and it fixes #2102.

This solves the problem simply by aborting the class mode whenever we see a <, > or =, and returning to the regular rule matching. This is a much simpler solution that trying to process deeply nested templates and count subexpressions of < vs ( - all the while trying to figure out what is perhaps simple a less than (or greater than) vs a template delimiter.

This also adds support for enum struct and enum class. This actually mostly worked before but now the "class" block extends around the "enum" as well which is slightly more correct I think.

  • Also adds a minor linting fix to quite a few tests regarding carriage return at the end of file.

See tests.

@klmr

Copy link
Contributor

@klmr klmr left a comment

Choose a reason for hiding this comment

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

This still doesn’t handle attributes, e.g.

struct [[deprecated]] foobar {};

Of course a simple fix would be to add |\[\[ to end but handling them properly isn’t actually much harder: we might just need a nested rule {begin: /\[\[/, end: /]]/, keywords: 'using'}.

But I wouldn’t increase the scope of this PR, as such attributes still relatively rare in C++ code (and even rarer on type declarations).

src/languages/c-like.js Outdated Show resolved Hide resolved
src/languages/c-like.js Outdated Show resolved Hide resolved
test/markup/cpp/template_complexity.txt Outdated Show resolved Hide resolved
@joshgoebel
Copy link
Member Author

But I wouldn’t increase the scope of this PR, as such attributes still relatively rare in C++ code (and even rarer on type declarations).

Thanks!

@joshgoebel
Copy link
Member Author

@klmr Better?

@joshgoebel joshgoebel merged commit 6d6b8a6 into highlightjs:master Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants