Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Core Grammars:
- fix(yaml) - Fixed wrong escaping behavior in single quoted strings [guuido]
- enh(nim) - Add `concept` and `defer` to list of Nim keywords [Jake Leahy]
- fix(cpp) - Exclude keywords from highlighting as function calls [Eisenwave]
- enh(cpp) add C++26 keywords, `#embed`, and compiler-builtin types [Eisenwave]

New Grammars:

Expand Down
9 changes: 7 additions & 2 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function(hljs) {
begin: /#\s*[a-z]+\b/,
end: /$/,
keywords: { keyword:
'if else elif endif define undef warning error line '
'if else elif embed endif define undef warning error line '
+ 'pragma _Pragma ifdef ifndef include' },
contains: [
{
Expand Down Expand Up @@ -151,6 +151,7 @@ export default function(hljs) {
'constexpr',
'constinit',
'continue',
'contract_assert',
'decltype',
'default',
'delete',
Expand Down Expand Up @@ -181,8 +182,10 @@ export default function(hljs) {
'or',
'or_eq',
'override',
'pre',
'private',
'protected',
'post',
'public',
'reflexpr',
'register',
Expand Down Expand Up @@ -212,7 +215,9 @@ export default function(hljs) {
'volatile',
'while',
'xor',
'xor_eq'
'xor_eq',
'_Atomic',
'_BitInt'
];

// https://en.cppreference.com/w/cpp/keyword
Expand Down
4 changes: 4 additions & 0 deletions test/markup/cpp/function-declarations.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
<span class="hljs-function"><span class="hljs-keyword">explicit</span> <span class="hljs-title">A</span><span class="hljs-params">()</span>: a(<span class="hljs-number">10</span>) {</span>}

<span class="hljs-function"><span class="hljs-keyword">extern</span> <span class="hljs-type">void</span> <span class="hljs-title">f</span><span class="hljs-params">(<span class="hljs-type">int</span>)</span>, <span class="hljs-title">g</span><span class="hljs-params">(<span class="hljs-type">char</span>)</span></span>;

<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">throwing</span><span class="hljs-params">(<span class="hljs-type">int</span> x)</span> <span class="hljs-keyword">noexcept</span>(<span class="hljs-literal">false</span>)</span>;
<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">deleted</span><span class="hljs-params">()</span> </span>= <span class="hljs-keyword">delete</span>(<span class="hljs-string">&quot;reason&quot;</span>);
<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">contracts</span><span class="hljs-params">(<span class="hljs-type">int</span> x)</span> <span class="hljs-keyword">pre</span>(x &gt; <span class="hljs-number">10</span>) <span class="hljs-keyword">post</span>(r : r != <span class="hljs-number">0</span>)</span>;
4 changes: 4 additions & 0 deletions test/markup/cpp/function-declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ void A(): a(10) {}
explicit A(): a(10) {}

extern void f(int), g(char);

void throwing(int x) noexcept(false);
void deleted() = delete("reason");
void contracts(int x) pre(x > 10) post(r : r != 0);
6 changes: 4 additions & 2 deletions test/markup/cpp/function-like-keywords.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<span class="hljs-keyword">for</span> (;;) {}

<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">f</span><span class="hljs-params">()</span> </span>= <span class="hljs-keyword">delete</span>(<span class="hljs-string">&quot;reason&quot;</span>);

<span class="hljs-keyword">static_assert</span>(<span class="hljs-literal">true</span>);
<span class="hljs-keyword">contract_assert</span>(<span class="hljs-literal">false</span>);

<span class="hljs-keyword">_BitInt</span>(<span class="hljs-number">64</span>) x;
<span class="hljs-keyword">_Atomic</span>(<span class="hljs-type">int</span>) y;
6 changes: 4 additions & 2 deletions test/markup/cpp/function-like-keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ while (ch) {}

for (;;) {}

void f() = delete("reason");

static_assert(true);
contract_assert(false);

_BitInt(64) x;
_Atomic(int) y;
Loading