You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect highlighting for C++ special identifiers #8745
Describe the bug
C++ identifiers with special meaning (final, override, import and module). are incorrectly highlighted out-of-context. These keywords should be considered as regular identifiers when used out of their special meaning context (c.f. C++20 standard, section 5.10, paragraph 2).
To Reproduce
Run vim --clean
Edit a.cc
Type 'int final, override, import, module;'
Incorrect highlighting for these variables name
Expected behavior
Highlighting for these variables names should be the same as the one for int x;
Environment (please complete the following information):
Vim version 8.2.3323
This is probably difficult to do properly as C++ syntax is complex and Vim does not use a C++ parser, but uses heuristics based on regexp for syntax highlighting. We can maybe improve heuristics, but we can't expect to get syntax highlighting it 100% right with heuristics. In practice, it's already doing a fairly good job for C++. Calling variables override,final or module seems quite rare and is asking for trouble. I understand that C++ allowed that for to avoid breaking existing software. Backward compatibility is important for C++. For Vim, the cost / benefit of fixing this ticket seems low IMO.
The only way to syntax highlight C++ (and other languages) 100% correctly, is to have a real C++ parser using e.g. Tree-sitter. Maybe something for Vim-10? :-)
This is probably difficult to do properly as C++ syntax is complex and
Vim does not use a C++ parser, but uses heuristics based on regexp for
syntax highlighting. We can maybe improve heuristics, but we can't
expect to get syntax highlighting it 100% right with heuristics. In
practice, it's already doing a fairly good job for C++. Calling
variables `override`,`final` or `module` seems quite a rare and is
asking for trouble. I understand that C++ allowed that for to avoid
breaking existing software. Backward compatibility is important for
C++. For Vim, the cost / benefit of fixing this ticket seems low IMO.
The only way to syntax highlight C++ correctly (and other languages)
100% correctly, is to have a real C++ parser using e.g. Tree-sitter.
Maybe something for Vim-10? :-)
I know someone was working on Tree-sitter, and it was not easy. Is it
working now? Evaluating the advantages and disadvantages would be a
good idea. I would expect it to behave very different from the
pattern-based syntax highlighting. E.g., how well does it handle syntax
errors? What happens while typing? Is there a noticeable delay when
opening a large file? Does it solve the slowness of long lines (e.g.
with XML)?
--
Hacker: Someone skilled in computer programming (good guy).
Cracker: A hacker that uses his skills to crack software (bad guy).
/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Activity
chrisbra commentedon Aug 30, 2021
That is a CPP syntax issue. So I'll leave that for https://github.com/vim-jp/vim-cpp
dpelle commentedon Aug 30, 2021
This is probably difficult to do properly as C++ syntax is complex and Vim does not use a C++ parser, but uses heuristics based on regexp for syntax highlighting. We can maybe improve heuristics, but we can't expect to get syntax highlighting it 100% right with heuristics. In practice, it's already doing a fairly good job for C++. Calling variables
override,finalormoduleseems quite rare and is asking for trouble. I understand that C++ allowed that for to avoid breaking existing software. Backward compatibility is important for C++. For Vim, the cost / benefit of fixing this ticket seems low IMO.The only way to syntax highlight C++ (and other languages) 100% correctly, is to have a real C++ parser using e.g. Tree-sitter. Maybe something for Vim-10? :-)
chrisbra commentedon Aug 30, 2021
yes, related: #8658
Note, Vim cannot do semantic highlighting (yet), just regex based highlighting.
brammool commentedon Aug 30, 2021
chrisbra commentedon Aug 30, 2021
apparently it works quite nicely for Neovim (for languages that have treesitter parsers).