From cc2bd2547b36b6d878de56af67df2741db32aa2d Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Mon, 23 Dec 2019 18:38:22 -0500 Subject: [PATCH] - enh(cpp) template type in function declaration Closes #1502. --- src/languages/cpp.js | 9 ++++++--- test/markup/cpp/function-declarations.expect.txt | 3 +++ test/markup/cpp/function-declarations.txt | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/languages/cpp.js b/src/languages/cpp.js index b38f0c30fc..78ac5d5634 100644 --- a/src/languages/cpp.js +++ b/src/languages/cpp.js @@ -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' @@ -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 diff --git a/test/markup/cpp/function-declarations.expect.txt b/test/markup/cpp/function-declarations.expect.txt index 414721bfc4..5189214025 100644 --- a/test/markup/cpp/function-declarations.expect.txt +++ b/test/markup/cpp/function-declarations.expect.txt @@ -10,4 +10,7 @@ B::type test() {}; +// template +boost::optional<application> handle_key(application state, key_code key, coord size); + test(); diff --git a/test/markup/cpp/function-declarations.txt b/test/markup/cpp/function-declarations.txt index 318a5b0a33..d196f5ca83 100644 --- a/test/markup/cpp/function-declarations.txt +++ b/test/markup/cpp/function-declarations.txt @@ -10,4 +10,7 @@ int8_t Get_Tile_Value() {} B::type test() {}; +// template +boost::optional handle_key(application state, key_code key, coord size); + test();