diff --git a/CHANGES.md b/CHANGES.md index b1413c29a5..c2788a984b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ Core Grammars: - enh(json) add json5 support [Kerry Shetline][] - fix(css) `unicode-range` parsing, issue #4253 [Kerry Shetline][] - fix(csharp) Support digit separators [te-ing][] +- fix(cpp) allow function names that start with reserved keyword prefixes [Puneet Dixit][] Documentation: @@ -55,6 +56,7 @@ CONTRIBUTORS [te-ing]: https://github.com/te-ing [Anthony Martin]: https://github.com/anthony-c-martin [NriotHrreion]: https://github.com/NriotHrreion +[Puneet Dixit]: https://github.com/puneetdixit200 ## Version 11.11.1 diff --git a/src/languages/cpp.js b/src/languages/cpp.js index 1b3e337784..49f7a42de0 100644 --- a/src/languages/cpp.js +++ b/src/languages/cpp.js @@ -417,6 +417,10 @@ export default function(hljs) { _type_hints: TYPE_HINTS }; + const RESERVED_KEYWORD_RE = regex.either( + ...RESERVED_KEYWORDS.map(keyword => keyword.replace(/\|\d+$/, '')) + ); + const FUNCTION_DISPATCH = { className: 'function.dispatch', relevance: 0, @@ -425,7 +429,7 @@ export default function(hljs) { _hint: FUNCTION_HINTS }, begin: regex.concat( /\b/, - `(?!${RESERVED_KEYWORDS.join('|')})`, + `(?!${RESERVED_KEYWORD_RE}\\b)`, hljs.IDENT_RE, regex.lookahead(/(<[^<>]+>|)\s*\(/)) }; diff --git a/test/markup/cpp/function-like-keywords.expect.txt b/test/markup/cpp/function-like-keywords.expect.txt index 2f6e266e58..c3db088541 100644 --- a/test/markup/cpp/function-like-keywords.expect.txt +++ b/test/markup/cpp/function-like-keywords.expect.txt @@ -10,3 +10,15 @@ void f() = delete("reason"); static_assert(true); + +format(); + +for_this(); + +whilexyz(); + +if (ifsyz()) {} + +returnxyz(); + +thisxyz(); diff --git a/test/markup/cpp/function-like-keywords.txt b/test/markup/cpp/function-like-keywords.txt index 608611fa8d..7ec3ee2e39 100644 --- a/test/markup/cpp/function-like-keywords.txt +++ b/test/markup/cpp/function-like-keywords.txt @@ -10,3 +10,15 @@ for (;;) {} void f() = delete("reason"); static_assert(true); + +format(); + +for_this(); + +whilexyz(); + +if (ifsyz()) {} + +returnxyz(); + +thisxyz();