From 7355c13512374e14b93f7124f67e71d300924f4c Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 29 Dec 2021 07:01:45 -0500 Subject: [PATCH] fix(cpp) `vector<<` false positive as template begin (#3438) --- CHANGES.md | 1 + src/languages/cpp.js | 2 +- test/markup/cpp/bugs.expect.txt | 6 ++++++ test/markup/cpp/bugs.txt | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/markup/cpp/bugs.expect.txt create mode 100644 test/markup/cpp/bugs.txt diff --git a/CHANGES.md b/CHANGES.md index b5c98322d9..071402f28d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ These changes should be for the better and should not be super noticeable but if Grammars: - enh(php) add PHP 8.1 keywords [Wojciech Kania][] +- fix(cpp) fix `vector<<` template false positive (#3437) [Josh Goebel][] - enh(php) support First-class Callable Syntax (#3427) [Wojciech Kania][] - enh(php) support class constructor call (#3427) [Wojciech Kania][] - enh(php) support function invoke (#3427) [Wojciech Kania][] diff --git a/src/languages/cpp.js b/src/languages/cpp.js index e2cf5a9d28..54e3bced7d 100644 --- a/src/languages/cpp.js +++ b/src/languages/cpp.js @@ -558,7 +558,7 @@ export default function(hljs) { [ PREPROCESSOR, { // containers: ie, `vector rooms (9);` - begin: '\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function)\\s*<', + begin: '\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function)\\s*<(?!<)', end: '>', keywords: CPP_KEYWORDS, contains: [ diff --git a/test/markup/cpp/bugs.expect.txt b/test/markup/cpp/bugs.expect.txt new file mode 100644 index 0000000000..08e8689dfc --- /dev/null +++ b/test/markup/cpp/bugs.expect.txt @@ -0,0 +1,6 @@ +//4. 对角矩阵 +//4.1 构造对角矩阵 +Eigen::VectorXd vector(5); //构建5维向量 +vector<<1,2,3,4,5; //向量赋值 +Eigen::MatrixXd C(vector.asDiagonal()); //使用向量生成对角阵 +std::cout << "\nC= \n" << C << std::endl; diff --git a/test/markup/cpp/bugs.txt b/test/markup/cpp/bugs.txt new file mode 100644 index 0000000000..00c4281821 --- /dev/null +++ b/test/markup/cpp/bugs.txt @@ -0,0 +1,6 @@ +//4. 对角矩阵 +//4.1 构造对角矩阵 +Eigen::VectorXd vector(5); //构建5维向量 +vector<<1,2,3,4,5; //向量赋值 +Eigen::MatrixXd C(vector.asDiagonal()); //使用向量生成对角阵 +std::cout << "\nC= \n" << C << std::endl;