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

fix(cpp): Allow declaring multiple functions and parenthetical initializers #3155

Merged
merged 5 commits into from
Apr 22, 2021
Merged
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Grammars:
- enh(haskell) add support for BinaryLiterals (#3150) [Martijn Bastiaan][]
- enh(haskell) add support for NumericUnderscores (#3150) [Martijn Bastiaan][]
- enh(haskell) add support for HexFloatLiterals (#3150) [Martijn Bastiaan][]
- fix(c,cpp) allow declaring multiple functions and (for C++) parenthetical initializers (#3155) [Erik Demaine][]

New Languages:

Expand Down Expand Up @@ -869,6 +870,7 @@ Language Improvements:
[Mike Schall]: https://github.com/schallm
[Kirill Saksin]: https://github.com/saksmt
[Samia Ali]:https://github.com/samiaab1990
[Erik Demaine]:https://github.com/edemaine


## Version 9.16.2
Expand Down
6 changes: 6 additions & 0 deletions src/languages/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ export default function(hljs) {
],
relevance: 0
},
// allow for multiple declarations, e.g.:
// extern void f(int), g(char);
{
relevance: 0,
match: /,/
},
{
className: 'params',
begin: /\(/,
Expand Down
6 changes: 6 additions & 0 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ export default function(hljs) {
NUMBERS
]
},
// allow for multiple declarations, e.g.:
Copy link
Member

Choose a reason for hiding this comment

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

LOL.

// extern void f(int), g(char);
{
relevance: 0,
match: /,/
},
{
className: 'params',
begin: /\(/,
Expand Down
2 changes: 2 additions & 0 deletions test/markup/cpp/function-declarations.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@

<span class="hljs-function"><span class="hljs-keyword">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-keyword">void</span> <span class="hljs-title">f</span><span class="hljs-params">(<span class="hljs-keyword">int</span>)</span>, <span class="hljs-title">g</span><span class="hljs-params">(<span class="hljs-keyword">char</span>)</span></span>;
2 changes: 2 additions & 0 deletions test/markup/cpp/function-declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ test();

void A(): a(10) {}
explicit A(): a(10) {}

extern void f(int), g(char);
2 changes: 2 additions & 0 deletions test/markup/cpp/initializers.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span class="hljs-function">string <span class="hljs-title">a</span><span class="hljs-params">(<span class="hljs-string">&quot;hello&quot;</span>)</span>, <span class="hljs-title">b</span><span class="hljs-params">(<span class="hljs-string">&quot;world&quot;</span>)</span></span>;
<span class="hljs-function">vector&lt;<span class="hljs-keyword">int</span>&gt; <span class="hljs-title">u</span><span class="hljs-params">(<span class="hljs-number">1</span>)</span>, <span class="hljs-title">v</span><span class="hljs-params">(<span class="hljs-number">2</span>)</span></span>;

Choose a reason for hiding this comment

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

Why do you think it is declaring four functions? To me I think it's initializing four variables.

Copy link
Member

Choose a reason for hiding this comment

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

If you have found a potential problem please open a new issue rather than commenting on a 3 year old issue.

2 changes: 2 additions & 0 deletions test/markup/cpp/initializers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
string a("hello"), b("world");
vector<int> u(1), v(2);