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

Commit

Permalink
Fix binary literal digit separator in C++ lexer (rouge-ruby#1620)
Browse files Browse the repository at this point in the history
The C++ lexer uses `_` as a digit separator for binary literals. This
is syntactically incorrect. The digit separator in C++ is `'`. This
commit fixes that error.

Co-authored-by: Stuart <stuart.wheaton@jhuapl.edu>
Co-authored-by: Michael Camilleri <mike@inqk.net>
  • Loading branch information
3 people authored and mattt committed May 19, 2021
1 parent 7e93843 commit d66c0e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/cpp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def self.reserved
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
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
rule %r/0b[01]+('[01]+)*/, Num::Bin
rule %r/0[0-7]('?[0-7])*[lu]*/i, Num::Oct
rule %r/#{dq}[lu]*/i, Num::Integer
rule %r/\bnullptr\b/, Name::Builtin
Expand Down
9 changes: 4 additions & 5 deletions spec/visual/samples/cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
int quote_delims = 100'000'000
int float_delims = 100.00'00
int hex_delims = 0xFF'Fa12

int binary = 0b1000;
int quote_delims = 100'000'000;
int float_delims = 100.00'00;
int hex_delims = 0xFF'Fa12;
int bin_delims = 0b10'1000;

// string literal with encoding-prefix
char str1[] = u8"UTF-8 string";
Expand Down

0 comments on commit d66c0e1

Please sign in to comment.