Skip to content

Commit

Permalink
- enh(cpp) template type in function declaration
Browse files Browse the repository at this point in the history
Closes #1502.
  • Loading branch information
joshgoebel committed Dec 23, 2019
1 parent 2027309 commit cc2bd25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/languages/cpp.js
Expand Up @@ -12,8 +12,11 @@ function(hljs) {
}
var DECLTYPE_AUTO_RE = 'decltype\\(auto\\)'
var NAMESPACE_RE = '[a-zA-Z_]\\w*::'
// (<.*?>)?
var FUNCTION_TYPE_RE = '(' + DECLTYPE_AUTO_RE + '|' + optional(NAMESPACE_RE) +'[a-zA-Z_]\\w*)';
var TEMPLATE_ARGUMENT_RE = '<.*?>';
var FUNCTION_TYPE_RE = '(' +
DECLTYPE_AUTO_RE + '|' +
optional(NAMESPACE_RE) +'[a-zA-Z_]\\w*' + optional(TEMPLATE_ARGUMENT_RE) +
')';
var CPP_PRIMITIVE_TYPES = {
className: 'keyword',
begin: '\\b[a-z\\d_]*_t\\b'
Expand Down Expand Up @@ -139,7 +142,7 @@ function(hljs) {
returnBegin: true, end: /[{;=]/,
excludeEnd: true,
keywords: CPP_KEYWORDS,
illegal: /[^\w\s\*&:]/,
illegal: /[^\w\s\*&:<>]/,
contains: [

{ // to prevent it from being confused as the function title
Expand Down
3 changes: 3 additions & 0 deletions test/markup/cpp/function-declarations.expect.txt
Expand Up @@ -10,4 +10,7 @@

<span class="hljs-function">B::type <span class="hljs-title">test</span><span class="hljs-params">()</span> </span>{};

<span class="hljs-comment">// template</span>
<span class="hljs-function">boost::optional&lt;application&gt; <span class="hljs-title">handle_key</span><span class="hljs-params">(application state, key_code key, coord size)</span></span>;

test();
3 changes: 3 additions & 0 deletions test/markup/cpp/function-declarations.txt
Expand Up @@ -10,4 +10,7 @@ int8_t Get_Tile_Value() {}

B::type test() {};

// template
boost::optional<application> handle_key(application state, key_code key, coord size);

test();

0 comments on commit cc2bd25

Please sign in to comment.