Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp Lexer: Updates for Standard Library User-Defined Literals (chrono, complex) #1665

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
dblessing marked this conversation as resolved.
Show resolved Hide resolved
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