Skip to content

Commit

Permalink
fix(c,cpp): Allow declaring multiple functions and parenthetical init…
Browse files Browse the repository at this point in the history
…ializers (#3155)

Co-authored-by: Josh Goebel <me@joshgoebel.com>
  • Loading branch information
edemaine and joshgoebel authored Apr 22, 2021
1 parent 3ff2bdb commit 570bbd5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 0 deletions.
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.:
// 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>;
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);

0 comments on commit 570bbd5

Please sign in to comment.