Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Support template parameter packs in C++ lexer (rouge-ruby#1555)
Browse files Browse the repository at this point in the history
The change in rouge-ruby#1495 to the way that the `template` keyword caused
template parameter packs not to be highlighted correctly. This commit
fixes that bug while also introducing a more robust set of rules for
highlighting identifiers succeeding the `template` keyword.
  • Loading branch information
pyrmont authored and mattt committed May 19, 2021
1 parent b709b65 commit 5c63ec4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rouge/lexers/cpp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ def self.reserved
rule id, Name::Class, :pop!

# template specification
rule %r/\s*(?=>)/m, Text, :pop!
rule %r/[.]{3}/, Operator
mixin :whitespace
rule %r/[.]{3}/, Operator
rule %r/,/, Punctuation, :pop!
rule(//) { pop! }
end

state :template do
rule %r/>/, Punctuation, :pop!
rule %r/[>;]/, Punctuation, :pop!
rule %r/typename\b/, Keyword, :classname
mixin :root
mixin :statements
end

state :case do
Expand Down
3 changes: 3 additions & 0 deletions spec/visual/samples/cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ template struct Z<double>;
template<typename T> concept C1 = sizeof(T) != sizeof(int);
template<C1 T> struct S1 { };
template<C1 T> using Ptr = T*;
template <typename, typename...>
template<class...> struct Tuple { };
template<typename ...Ts> void f(Ts...) {}

// variadic template
template<class F, class... Args>
Expand Down

0 comments on commit 5c63ec4

Please sign in to comment.