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

Add operator detecting for c/cpp #3964

Open
wants to merge 137 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
ae71926
Update cpp.js
TOMWT-qwq Jan 13, 2024
7eb71cd
Update cpp.js
TOMWT-qwq Jan 13, 2024
8b06206
Update cpp.js
TOMWT-qwq Jan 13, 2024
c119ef1
Update cpp.js
TOMWT-qwq Jan 14, 2024
d321277
Update CHANGES.md
TOMWT-qwq Jan 14, 2024
5f93501
Update CHANGES.md
TOMWT-qwq Jan 14, 2024
2f91b37
Update CHANGES.md
TOMWT-qwq Jan 14, 2024
a07c92b
Update cpp.js
TOMWT-qwq Jan 14, 2024
7f99840
Update CHANGES.md
TOMWT-qwq Jan 14, 2024
523b7b5
Update cpp.js
TOMWT-qwq Jan 14, 2024
2a50233
clean up and simply PR
joshgoebel Jan 14, 2024
bdd303c
Update cpp.js
TOMWT-qwq Jan 15, 2024
5c0b290
Update cpp.js
TOMWT-qwq Jan 15, 2024
d9360e7
Update cpp.js
TOMWT-qwq Jan 15, 2024
1b5949a
Update cpp.js
TOMWT-qwq Jan 15, 2024
349f398
Update cpp.js
TOMWT-qwq Jan 15, 2024
75ba6ee
Update cpp.js
TOMWT-qwq Jan 15, 2024
071577e
Update CHANGES.md
TOMWT-qwq Jan 15, 2024
7d9d5c7
link in regex.escape
joshgoebel Jan 16, 2024
d654f38
Update bitwise-keywords.expect.txt
tomwt-awa Jan 16, 2024
e958fcc
Update bugs.expect.txt
tomwt-awa Jan 16, 2024
5406e47
Update cpp.js
tomwt-awa Jan 16, 2024
e5a8d20
Update expression-keywords.expect.txt
tomwt-awa Jan 16, 2024
12a02fe
Update cpp.js
tomwt-awa Jan 16, 2024
95724ea
Update function-params.expect.txt
tomwt-awa Jan 16, 2024
b0c0597
Update cpp.js
tomwt-awa Jan 16, 2024
cb5015c
Update cpp.js
tomwt-awa Jan 17, 2024
7f9a622
Update default.expect.txt
tomwt-awa Jan 17, 2024
19d7bae
Update string-literals.expect.txt
tomwt-awa Jan 17, 2024
37feeb5
Update preprocessor.expect.txt
tomwt-awa Jan 17, 2024
5f3966c
Update number-literals.expect.txt
tomwt-awa Jan 17, 2024
7d18588
Update function-declarations.txt
tomwt-awa Jan 17, 2024
ad93c09
Update c.js
TOMWT-qwq Jan 17, 2024
21b1994
Update cpp.js
TOMWT-qwq Jan 17, 2024
fb6b736
Update c.js
TOMWT-qwq Jan 17, 2024
de48b55
Update cpp.js
TOMWT-qwq Jan 17, 2024
646dafa
Update function-declarations.expect.txt
TOMWT-qwq Jan 17, 2024
f61cf32
Update function-title.expect.txt
TOMWT-qwq Jan 17, 2024
7b92fa5
Update c.js
TOMWT-qwq Jan 17, 2024
b7e2ed0
Update cpp.js
TOMWT-qwq Jan 17, 2024
dbcb2fc
Update c.js
TOMWT-qwq Jan 17, 2024
372fa17
Update cpp.js
TOMWT-qwq Jan 17, 2024
10f340c
Update c.js
TOMWT-qwq Jan 17, 2024
92956cb
Update cpp.js
TOMWT-qwq Jan 17, 2024
f06c1e9
Update cpp.js
TOMWT-qwq Jan 17, 2024
3b8812b
Update cpp.js
TOMWT-qwq Jan 17, 2024
ca4ad5b
Update cpp.js
TOMWT-qwq Jan 17, 2024
ef84dd7
Update cpp.js
TOMWT-qwq Jan 17, 2024
d9474fc
Update cpp.js
TOMWT-qwq Jan 17, 2024
d39e33d
Update cpp.js
TOMWT-qwq Jan 17, 2024
b1fec56
Merge pull request #4 from highlightjs/main
TOMWT-qwq Jan 19, 2024
aa00329
Update cpp.js
tomwt-awa Jan 20, 2024
291a7e5
Update c.js
tomwt-awa Jan 20, 2024
3f2ac85
Update function-declarations.expect.txt
tomwt-awa Jan 20, 2024
2d4825e
Update function-title.expect.txt
tomwt-awa Jan 20, 2024
674cbc6
Update function-declarations.expect.txt
tomwt-awa Jan 20, 2024
82c65b5
Update function-title.expect.txt
tomwt-awa Jan 20, 2024
85cf255
Update function-declarations.expect.txt
tomwt-awa Jan 20, 2024
8bb807d
Update primitive-types.expect.txt
tomwt-awa Jan 20, 2024
dbae28a
Update template-complexity.expect.txt
tomwt-awa Jan 20, 2024
d9eb372
Update cpp.js
tomwt-awa Jan 20, 2024
4e9d9c8
Update primitive-types.expect.txt
tomwt-awa Jan 20, 2024
f661965
Update template-complexity.expect.txt
tomwt-awa Jan 20, 2024
31b522f
Update c.js
tomwt-awa Jan 20, 2024
766973e
Update cpp.js
tomwt-awa Jan 20, 2024
f17b01a
Create operators.txt
tomwt-awa Jan 20, 2024
53573e6
Create operator.expect.txt
tomwt-awa Jan 20, 2024
8f43319
Delete test/markup/cpp/operator.expect.txt
tomwt-awa Jan 20, 2024
a46ae69
Create operators.expect.txt
tomwt-awa Jan 20, 2024
7cc1ede
Update operators.expect.txt
tomwt-awa Jan 20, 2024
bc8ff34
Update cpp.js
TOMWT-qwq Jan 20, 2024
717cfc5
Update function-title.expect.txt
TOMWT-qwq Jan 20, 2024
670854c
Merge pull request #7 from TOMWT-qwq/test
TOMWT-qwq Jan 20, 2024
0b5fca8
Update function-title.expect.txt
TOMWT-qwq Jan 20, 2024
d2f86a5
Update template-complexity.expect.txt
TOMWT-qwq Jan 20, 2024
bccbcf1
Merge branch 'main' into patch-1
TOMWT-qwq Jan 21, 2024
acca3b5
Update c.js
TOMWT-qwq Jan 21, 2024
e268836
Update cpp.js
TOMWT-qwq Jan 21, 2024
2134bf4
Update cpp.js
TOMWT-qwq Jan 21, 2024
5199d56
Update cpp.js
TOMWT-qwq Jan 21, 2024
a2e70d7
Update c.js
tomwt-awa Jan 21, 2024
80f0ed1
Update cpp.js
tomwt-awa Jan 21, 2024
529d225
Update c.js
tomwt-awa Jan 21, 2024
bbb0284
Update cpp.js
tomwt-awa Jan 21, 2024
b789408
Update cpp.js
tomwt-awa Jan 21, 2024
af6d69e
Update cpp.js
tomwt-awa Jan 21, 2024
f723bc5
Update cpp.js
tomwt-awa Jan 21, 2024
2250e06
Update function-declarations.txt
TOMWT-qwq Jan 21, 2024
8017a4d
Update function-declarations.expect.txt
TOMWT-qwq Jan 21, 2024
dbd21e5
Update operators.txt
TOMWT-qwq Jan 21, 2024
d85ec53
Update operators.expect.txt
TOMWT-qwq Jan 21, 2024
97eeb05
Update cpp.js
TOMWT-qwq Jan 21, 2024
1044882
Update CHANGES.md
TOMWT-qwq Jan 22, 2024
2dccb73
Update cpp.js
TOMWT-qwq Jan 22, 2024
f951335
Update CHANGES.md
tomwt-awa Jan 23, 2024
b3b7cb1
Update cpp.js
tomwt-awa Jan 23, 2024
6b8aae5
Update cpp.js
tomwt-awa Jan 23, 2024
c7034db
Update bugs.expect.txt
tomwt-awa Jan 23, 2024
ac95ee3
Update function-declarations.expect.txt
tomwt-awa Jan 23, 2024
571a7c5
Update operators.expect.txt
tomwt-awa Jan 23, 2024
f1f131b
Update cpp.js
tomwt-awa Jan 23, 2024
c1629bd
Update template-complexity.txt
tomwt-awa Jan 23, 2024
0b1e8fa
Update template-complexity.expect.txt
tomwt-awa Jan 23, 2024
acae136
Update function-declarations.expect.txt
tomwt-awa Jan 23, 2024
985ab3f
Update cpp.js
tomwt-awa Jan 23, 2024
aa14119
Update cpp.js
tomwt-awa Jan 23, 2024
d427e0b
Update cpp.js
tomwt-awa Jan 23, 2024
3cae087
Update cpp.js
tomwt-awa Jan 23, 2024
8b6008a
Update cpp.js
tomwt-awa Jan 23, 2024
19979fe
Update cpp.js
tomwt-awa Jan 23, 2024
033a25b
Update cpp.js
tomwt-awa Jan 23, 2024
6ab2a3a
Update cpp.js
tomwt-awa Jan 23, 2024
d75798a
Update function-declarations.expect.txt
tomwt-awa Jan 23, 2024
fb31034
Update operators.expect.txt
tomwt-awa Jan 23, 2024
2c951fb
Update function-declarations.expect.txt
tomwt-awa Jan 23, 2024
4275525
Update cpp.js
TOMWT-qwq Jan 23, 2024
73fbcd2
Update function-declarations.expect.txt
TOMWT-qwq Jan 23, 2024
947ab51
Update operators.expect.txt
TOMWT-qwq Jan 23, 2024
89ab28e
Update CHANGES.md
TOMWT-qwq Jan 23, 2024
69b2a41
Update c.js
tomwt-awa Jan 24, 2024
a089e2c
Update CHANGES.md
tomwt-awa Jan 24, 2024
185dd8d
Update CHANGES.md
tomwt-awa Jan 24, 2024
2e90a07
Update c.js
tomwt-awa Jan 24, 2024
787692f
Update c.js
tomwt-awa Jan 24, 2024
46a4f27
Update cpp.js
tomwt-awa Jan 24, 2024
57e2eca
Update bugs.expect.txt
tomwt-awa Jan 24, 2024
e960809
Update function-declarations.expect.txt
tomwt-awa Jan 24, 2024
582b823
Update operators.expect.txt
tomwt-awa Jan 24, 2024
2cf37ee
Update operators.txt
tomwt-awa Jan 24, 2024
a07c668
Update operators.expect.txt
tomwt-awa Jan 24, 2024
a98b8f1
Update template-complexity.txt
TOMWT-qwq Jan 24, 2024
8cb6942
Update template-complexity.expect.txt
TOMWT-qwq Jan 24, 2024
d8c6b61
Update template-complexity.txt
TOMWT-qwq Jan 24, 2024
3269f61
Update template-complexity.expect.txt
TOMWT-qwq Jan 24, 2024
c7fd9fb
Update cpp.js
TOMWT-qwq Jan 24, 2024
1b41b95
Update cpp.js
TOMWT-qwq Jan 24, 2024
815d8fd
Merge branch 'main' into patch-1
TOMWT-qwq Jan 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -27,6 +27,8 @@ Core Grammars:
- fix(swift) ensure keyword attributes highlight correctly [Bradley Mackey][]
- fix(types) fix interface LanguageDetail > keywords [Patrick Chiu]
- enh(java) add `goto` to be recognized as a keyword in Java [Alvin Joy][]
- enh(cpp) add operator detecting [TOMWT-qwq][]
- fix(cpp) fix `FUNCTION_TITLE` not matching defining operator [TOMWT-qwq][]

New Grammars:

Expand Down
1 change: 1 addition & 0 deletions src/highlight.js
Expand Up @@ -1013,6 +1013,7 @@ const HLJS = function(hljs) {
hljs.versionString = packageJSON.version;

hljs.regex = {
escape: regex.escape,
concat: regex.concat,
lookahead: regex.lookahead,
either: regex.either,
Expand Down
55 changes: 53 additions & 2 deletions src/languages/c.js
Expand Up @@ -63,6 +63,54 @@ export default function(hljs) {
],
relevance: 0
};

const OPERATORS = [
'::',
'->',
'+=',
'-=',
'*=',
'/=',
'%=',
'&=',
'|=',
'^=',
'<<=',
'>>=',
'++',
'--',
'<<',
'>>',
'&&',
'||',
'<=>',
'==',
'!=',
'<=',
'>=',
'~',
'!',
'%',
'^',
'&',
'|',
'*',
'<',
'>',
'/',
'-',
'+',
'?',
':',
'=',
];
const OPERATOR_RE = regex.either(...OPERATORS.map(x => regex.escape(x)));

const OPERATOR = {
scope: 'operator',
match: OPERATOR_RE,
relevance: 0
};

const PREPROCESSOR = {
className: 'meta',
Expand All @@ -82,7 +130,8 @@ export default function(hljs) {
begin: /<.*?>/
},
C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
hljs.C_BLOCK_COMMENT_MODE,
OPERATOR,
]
};

Expand Down Expand Up @@ -183,6 +232,7 @@ export default function(hljs) {
TYPES,
C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
OPERATOR,
NUMBERS,
STRINGS
];
Expand All @@ -193,7 +243,7 @@ export default function(hljs) {
// `return some()`, `else if()`, `(x*sum(1, 2))`
variants: [
{
begin: /=/,
begin: regex.lookahead(/=/),
end: /;/
},
{
Expand Down Expand Up @@ -252,6 +302,7 @@ export default function(hljs) {
contains: [
C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
OPERATOR,
STRINGS,
NUMBERS,
TYPES,
Expand Down
71 changes: 66 additions & 5 deletions src/languages/cpp.js
Expand Up @@ -94,6 +94,56 @@ export default function(hljs) {
relevance: 0
};

const OPERATORS = [
'::',
'->',
'...',
'.',
'+=',
'-=',
'*=',
'/=',
'%=',
'&=',
'|=',
'^=',
'<<=',
'>>=',
'++',
'--',
'<<',
'>>',
'&&',
'||',
'<=>',
'==',
'!=',
'<=',
'>=',
'~',
'!',
'%',
'^',
'&',
'|',
'*',
'<',
'>',
'/',
'-',
'+',
'?',
':',
'=',
];
const OPERATOR_RE = regex.either(...OPERATORS.map(x => regex.escape(x)));

const OPERATOR = {
scope: 'operator',
match: OPERATOR_RE,
relevance: 0
};

const PREPROCESSOR = {
className: 'meta',
begin: /#\s*[a-z]+\b/,
Expand All @@ -112,17 +162,25 @@ export default function(hljs) {
begin: /<.*?>/
},
C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
hljs.C_BLOCK_COMMENT_MODE,
OPERATOR,
]
};

const TITLE_MODE = {
className: 'title',
begin: regex.optional(NAMESPACE_RE) + hljs.IDENT_RE,
scope: 'title',
keywords: "operator",
begin: regex.either(
regex.optional(NAMESPACE_RE) + hljs.IDENT_RE,
'operator\\s*' + OPERATOR_RE,
),
relevance: 0
};

const FUNCTION_TITLE = regex.optional(NAMESPACE_RE) + hljs.IDENT_RE + '\\s*\\(';
const FUNCTION_TITLE = regex.either(
regex.optional(NAMESPACE_RE) + hljs.IDENT_RE + '\\s*\\(',
'operator\\s*' + OPERATOR_RE + '\\s*\\(',
Copy link
Member

Choose a reason for hiding this comment

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

The string "operator" is not part of a function title... and if you are trying to highlight the operator itself as a title.function in these cases it'd be better to use a multi-matcher to do that... see the documentation for beginMatch... so we'd match:

"operator" [ws] [operator] and scope each segment differently.

Copy link
Author

Choose a reason for hiding this comment

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

struct test{
	int a,b;
	inline bool operator+(const test&kkk)const{return a+kkk.b;}
};

I mean to highlight "operator" because I've noticed this case. I think it's a part of function title.

Copy link
Member

Choose a reason for hiding this comment

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

Did you try the tools/developer.html tool? This already works without any additional
changes as I can tell.

Screen Shot 2024-01-20 at 12 23 21 PM

Copy link
Author

Choose a reason for hiding this comment

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

operator is detected as a keyword instead of title.

Copy link
Member

Choose a reason for hiding this comment

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

OH... I see what you're expecting now... hmmm... let me noodle on that...

Copy link
Author

Choose a reason for hiding this comment

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

What's your opinion? You mean "operator" is used to decorate the real operator?

Copy link
Author

Choose a reason for hiding this comment

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

Oh I think you are right after reading smth on cppreference.

Copy link
Author

Choose a reason for hiding this comment

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

So how to deal with the overloaded operator? title or operator?

Choose a reason for hiding this comment

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

But there is no <span class="hljs-function"></span> now.

Choose a reason for hiding this comment

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

Currently nothing is working properly :(

);

// https://en.cppreference.com/w/cpp/keyword
const RESERVED_KEYWORDS = [
Expand Down Expand Up @@ -438,6 +496,7 @@ export default function(hljs) {
CPP_PRIMITIVE_TYPES,
C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
OPERATOR,
NUMBERS,
STRINGS
];
Expand All @@ -448,7 +507,7 @@ export default function(hljs) {
// `return some()`, `else if()`, `(x*sum(1, 2))`
variants: [
{
begin: /=/,
begin: regex.lookahead(/=/),
end: /;/
},
{
Expand Down Expand Up @@ -504,6 +563,7 @@ export default function(hljs) {
begin: /:/,
endsWithParent: true,
contains: [
OPERATOR,
STRINGS,
NUMBERS
]
Expand All @@ -523,6 +583,7 @@ export default function(hljs) {
contains: [
C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
OPERATOR,
STRINGS,
NUMBERS,
CPP_PRIMITIVE_TYPES,
Expand Down
2 changes: 1 addition & 1 deletion test/markup/arduino/default.expect.txt
Expand Up @@ -7,7 +7,7 @@

<span class="hljs-comment">// Pin 13 has an LED connected on most Arduino boards.</span>
<span class="hljs-comment">// give it a name:</span>
<span class="hljs-type">int</span> led = <span class="hljs-number">13</span>;
<span class="hljs-type">int</span> led <span class="hljs-operator">=</span> <span class="hljs-number">13</span>;

<span class="hljs-comment">// the setup routine runs once when you press reset:</span>
<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">setup</span><span class="hljs-params">()</span> </span>{
Expand Down
10 changes: 5 additions & 5 deletions test/markup/cpp/bitwise-keywords.expect.txt
@@ -1,8 +1,8 @@
<span class="hljs-type">unsigned</span> <span class="hljs-type">char</span> a = <span class="hljs-number">0xFA</span>;
<span class="hljs-type">unsigned</span> <span class="hljs-type">char</span> b = <span class="hljs-number">0x4C</span>;
<span class="hljs-type">unsigned</span> <span class="hljs-type">char</span> a <span class="hljs-operator">=</span> <span class="hljs-number">0xFA</span>;
<span class="hljs-type">unsigned</span> <span class="hljs-type">char</span> b <span class="hljs-operator">=</span> <span class="hljs-number">0x4C</span>;

a = <span class="hljs-keyword">compl</span> b;
a = <span class="hljs-keyword">not</span> b;
a <span class="hljs-operator">=</span> <span class="hljs-keyword">compl</span> b;
a <span class="hljs-operator">=</span> <span class="hljs-keyword">not</span> b;
a <span class="hljs-keyword">and</span> b;
a <span class="hljs-keyword">bitor</span> b;
a <span class="hljs-keyword">or</span> b;
Expand All @@ -11,4 +11,4 @@ a <span class="hljs-keyword">bitand</span> b;
a <span class="hljs-keyword">and_eq</span> b;
a <span class="hljs-keyword">or_eq</span> b;
a <span class="hljs-keyword">xor_eq</span> b;
a <span class="hljs-keyword">not_eq</span> b;
a <span class="hljs-keyword">not_eq</span> b;
6 changes: 3 additions & 3 deletions test/markup/cpp/bugs.expect.txt
@@ -1,6 +1,6 @@
<span class="hljs-comment">//4. 对角矩阵</span>
<span class="hljs-comment">//4.1 构造对角矩阵</span>
<span class="hljs-function">Eigen::VectorXd <span class="hljs-title">vector</span><span class="hljs-params">(<span class="hljs-number">5</span>)</span></span>; <span class="hljs-comment">//构建5维向量</span>
vector&lt;&lt;<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>; <span class="hljs-comment">//向量赋值</span>
<span class="hljs-function">Eigen::MatrixXd <span class="hljs-title">C</span><span class="hljs-params">(vector.asDiagonal())</span></span>; <span class="hljs-comment">//使用向量生成对角阵</span>
std::cout &lt;&lt; <span class="hljs-string">&quot;\nC= \n&quot;</span> &lt;&lt; C &lt;&lt; std::endl;
vector<span class="hljs-operator">&lt;&lt;</span><span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>; <span class="hljs-comment">//向量赋值</span>
<span class="hljs-function">Eigen::MatrixXd <span class="hljs-title">C</span><span class="hljs-params">(vector<span class="hljs-operator">.</span>asDiagonal())</span></span>; <span class="hljs-comment">//使用向量生成对角阵</span>
std::cout <span class="hljs-operator">&lt;&lt;</span> <span class="hljs-string">&quot;\nC= \n&quot;</span> <span class="hljs-operator">&lt;&lt;</span> C <span class="hljs-operator">&lt;&lt;</span> std::endl;
2 changes: 1 addition & 1 deletion test/markup/cpp/expression-keywords.expect.txt
@@ -1,2 +1,2 @@
<span class="hljs-type">double</span> x = <span class="hljs-built_in">exp</span>(<span class="hljs-built_in">log</span>(<span class="hljs-number">2</span>)); <span class="hljs-comment">// recognize built-ins</span>
<span class="hljs-type">double</span> x <span class="hljs-operator">=</span> <span class="hljs-built_in">exp</span>(<span class="hljs-built_in">log</span>(<span class="hljs-number">2</span>)); <span class="hljs-comment">// recognize built-ins</span>
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; <span class="hljs-comment">// recognize keyword that started the expression</span>
11 changes: 9 additions & 2 deletions test/markup/cpp/function-declarations.expect.txt
Expand Up @@ -2,7 +2,7 @@
<span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">look_up_a_string_2</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-built_in">lookup2</span>(); }
<span class="hljs-function"><span class="hljs-keyword">friend</span> <span class="hljs-type">void</span> <span class="hljs-title">A::showB</span><span class="hljs-params">(B x)</span> </span>{}
<span class="hljs-function"><span class="hljs-keyword">friend</span> <span class="hljs-type">void</span> <span class="hljs-title">showB</span><span class="hljs-params">(B x)</span> </span>{}
<span class="hljs-function"><span class="hljs-keyword">friend</span> <span class="hljs-type">void</span> <span class="hljs-title">showB</span><span class="hljs-params">(B::SomeType x)</span> </span>{}
<span class="hljs-function"><span class="hljs-keyword">friend</span> <span class="hljs-type">void</span> <span class="hljs-title">showB</span><span class="hljs-params">(B<span class="hljs-operator">::</span>SomeType x)</span> </span>{}
<span class="hljs-function"><span class="hljs-keyword">inline</span> <span class="hljs-type">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-type">int</span> a, <span class="hljs-type">int</span> b)</span> </span>{}
<span class="hljs-function">int8t <span class="hljs-title">Get_Tile_Value</span><span class="hljs-params">()</span> </span>{}

Expand All @@ -15,11 +15,18 @@

<span class="hljs-comment">// pack expansion in function arguments</span>
<span class="hljs-function"><span class="hljs-keyword">template</span>&lt;<span class="hljs-keyword">typename</span> T...&gt;
<span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(T... args)</span> </span>{}
<span class="hljs-type">void</span> <span class="hljs-title">foo</span><span class="hljs-params">(T<span class="hljs-operator">...</span> args)</span> </span>{}

<span class="hljs-built_in">test</span>();

<span class="hljs-function"><span class="hljs-type">void</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">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-keyword">struct</span> <span class="hljs-title class_">test</span>{
<span class="hljs-type">int</span> a,b;
<span class="hljs-function"><span class="hljs-keyword">inline</span> <span class="hljs-title">test</span><span class="hljs-params">()</span>:a(<span class="hljs-number">1</span>),b(<span class="hljs-number">2llu</span>){</span>;a<span class="hljs-operator">+=</span>b<span class="hljs-operator">+=</span>a<span class="hljs-operator">^</span>b;;;}
<span class="hljs-function"><span class="hljs-keyword">inline</span> <span class="hljs-type">bool</span> <span class="hljs-title"><span class="hljs-keyword">operator</span></span>+<span class="hljs-params">(<span class="hljs-type">const</span> test<span class="hljs-operator">&amp;</span>kkk)</span><span class="hljs-type">const</span></span>{<span class="hljs-keyword">return</span> a<span class="hljs-operator">+</span>kkk<span class="hljs-operator">.</span>b;}
};
<span class="hljs-function"><span class="hljs-keyword">inline</span> <span class="hljs-type">void</span> <span class="hljs-title"><span class="hljs-keyword">operator</span></span>*</span>=(test<span class="hljs-operator">*</span>lll,test qqq){;;;<span class="hljs-operator">*</span>lll<span class="hljs-operator">+</span>qqq;}
7 changes: 7 additions & 0 deletions test/markup/cpp/function-declarations.txt
Expand Up @@ -23,3 +23,10 @@ void A(): a(10) {}
explicit A(): a(10) {}

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

struct test{
int a,b;
inline test():a(1),b(2llu){;a+=b+=a^b;;;}
inline bool operator+(const test&kkk)const{return a+kkk.b;}
};
inline void operator*=(test*lll,test qqq){;;;*lll+qqq;}
8 changes: 4 additions & 4 deletions test/markup/cpp/function-params.expect.txt
@@ -1,7 +1,7 @@
<span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">f</span><span class="hljs-params">(
<span class="hljs-type">int</span> a = <span class="hljs-number">1</span>,
<span class="hljs-type">char</span>* b = <span class="hljs-string">&quot;2&quot;</span>, <span class="hljs-comment">// Line comment</span>
<span class="hljs-type">double</span> c = <span class="hljs-number">3.0</span>, <span class="hljs-comment">/* Block comment */</span>
<span class="hljs-type">int</span> a <span class="hljs-operator">=</span> <span class="hljs-number">1</span>,
<span class="hljs-type">char</span><span class="hljs-operator">*</span> b <span class="hljs-operator">=</span> <span class="hljs-string">&quot;2&quot;</span>, <span class="hljs-comment">// Line comment</span>
<span class="hljs-type">double</span> c <span class="hljs-operator">=</span> <span class="hljs-number">3.0</span>, <span class="hljs-comment">/* Block comment */</span>
ARRAY(<span class="hljs-type">int</span>, <span class="hljs-number">5</span>) d,
<span class="hljs-type">void</span>* e __attribute__((unused))
<span class="hljs-type">void</span><span class="hljs-operator">*</span> e __attribute__((unused))
)</span></span>;
14 changes: 7 additions & 7 deletions test/markup/cpp/function-title.expect.txt
@@ -1,10 +1,10 @@
<span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-type">int</span> argc, <span class="hljs-type">char</span>** argv)</span> </span>{
<span class="hljs-keyword">auto</span> a = std::<span class="hljs-built_in">make_unique</span>&lt;A&gt;();
B *b = <span class="hljs-keyword">new</span> <span class="hljs-built_in">B</span>();
<span class="hljs-type">int</span> c = c * <span class="hljs-built_in">sum</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);
<span class="hljs-keyword">if</span> (a-&gt;<span class="hljs-built_in">check1</span>())
<span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-type">int</span> argc, <span class="hljs-type">char</span><span class="hljs-operator">*</span><span class="hljs-operator">*</span> argv)</span> </span>{
<span class="hljs-keyword">auto</span> a <span class="hljs-operator">=</span> std<span class="hljs-operator">::</span><span class="hljs-built_in">make_unique</span><span class="hljs-operator">&lt;</span>A<span class="hljs-operator">&gt;</span>();
B <span class="hljs-operator">*</span>b <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">B</span>();
<span class="hljs-type">int</span> c <span class="hljs-operator">=</span> c <span class="hljs-operator">*</span> <span class="hljs-built_in">sum</span>(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);
<span class="hljs-keyword">if</span> (a<span class="hljs-operator">-&gt;</span><span class="hljs-built_in">check1</span>())
<span class="hljs-keyword">return</span> <span class="hljs-number">3</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (a-&gt;<span class="hljs-built_in">check2</span>())
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (a<span class="hljs-operator">-&gt;</span><span class="hljs-built_in">check2</span>())
<span class="hljs-keyword">return</span> <span class="hljs-number">4</span>;
<span class="hljs-keyword">return</span> a-&gt;<span class="hljs-built_in">result</span>();
<span class="hljs-keyword">return</span> a<span class="hljs-operator">-&gt;</span><span class="hljs-built_in">result</span>();
}