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

Commit

Permalink
cpp lexer: add y/d chrono literals, add std::complex literals, fix ch…
Browse files Browse the repository at this point in the history
…rono literals with digit separator (rouge-ruby#1665)

Co-authored-by: Stuart <stuart.wheaton@jhuapl.edu>
  • Loading branch information
2 people authored and mattt committed May 19, 2021
1 parent b731a37 commit 5bee97d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/cpp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.reserved
prepend :statements do
rule %r/(class|struct)\b/, Keyword, :classname
rule %r/template\b/, Keyword, :template
rule %r/\d+(\.\d+)?(?:h|(?:min)|s|(?:ms)|(?:us)|(?:ns))/, Num::Other
rule %r/#{dq}(\.#{dq})?(?:y|d|h|(?:min)|s|(?:ms)|(?:us)|(?:ns)|i|(?:if)|(?:il))\b/, Num::Other
rule %r((#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?)i, Num::Float
rule %r(#{dq}e[+-]?#{dq}[lu]*)i, Num::Float
rule %r/0x\h('?\h)*[lu]*/i, Num::Hex
Expand Down
10 changes: 10 additions & 0 deletions spec/visual/samples/cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,24 @@ char16_t raw_str3[] = uR"(\w+ \d+)";
// time literal
#include <chrono>
using namespace std::chrono_literals;
auto oneDecade = 10y;
auto oneYear = 365.2'425d;
auto oneDay = 24h;
auto halfAnHour = 30min;
auto oneYearInMins = 525'949.2min;
auto halfAnHour = 0.5h;
auto oneMin = 60s;
auto oneSec = 1000ms;
auto oneMilliSec = 1000us;
auto oneMicroSec = 1000ns;

// complex literal
#include <complex>
using namespace std::complex_literals;
auto complexNumber = 1 + 1i;
auto complexNumberl = 1 + 1il;
auto complexNumberf = 1 + 1if;

// null pointer
int *a = nullptr;

Expand Down

0 comments on commit 5bee97d

Please sign in to comment.