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
(cpp) function declaration claims variable declarations incorrectly #1114
Comments
I've managed to reduce the example to its minimal expression: This is detected as perl and it throws Illegal lexeme "?" for mode "function" while detecting C++ This is correctly detected as C++ Two options are perfectly valid expressions in C++, and the first one is the only way to call object constructors in C++ 2003
|
Highlight.js relevance system works bad for such short pieces of code. On first piece:
|
@Sannis the actual problem is not mis-detection. We have a rather simplistic rule for highlighting function definitions, so anything that starts with I'm not sure how to fix it yet. One simple answer would be to simply drop highlighting function definitions altogether but that would remove a lot of relevance from C/C++ and degrade highlighting. |
Status update: I believe an oncoming backtracking parser (#1140) will allow us to constrain a function definition to only have something that looks like arguments within the parentheses, so it won't touch constructs like |
Related to #1222 |
If anyone gets around to this we should add tests for some of the great examples that can be found here: https://stackoverflow.com/a/4324780/12430243 Regarding lambdas, function within function, static type functions inside functions, etc. |
This is much improved since 2016 though... the code isn't flagged as illegal anymore... but it's still mistakenly assumed to be a function definition. |
Closing because:
Rather than leave issues like this potentially open forever I am closing. One day if we switch to a backtracking parser we can naturally re-review edge cases like this (among other things). |
In highlight.js 9.2, the following code isn't recognized as C++:
I detected the following throw while detecting the language:
Illegal lexeme "?" for mode "function"
The text was updated successfully, but these errors were encountered: