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

Commit

Permalink
Support additional number literals in the Ruby lexer (rouge-ruby#1456)
Browse files Browse the repository at this point in the history
Ruby supports number literals that include `_` and that include
exponents. This commit adds support for this syntax to the Ruby lexer.
  • Loading branch information
gfx authored and mattt committed May 21, 2020
1 parent aa87e5f commit 9d84c54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/rouge/lexers/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ def self.detect?(text)
rule %r/0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
rule %r/\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
rule %r/[\d]+(?:_\d+)*/, Num::Integer

decimal = %r/[\d]+(?:_\d+)*/
exp = %r/e[+-]?\d+/i
rule %r/#{decimal}(?:\.#{decimal}#{exp}?|#{exp})/, Num::Float
rule decimal, Num::Integer

# names
rule %r/@@[a-z_]\w*/i, Name::Variable::Class
Expand Down
3 changes: 3 additions & 0 deletions spec/visual/samples/ruby
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ end

# It appears in Floats
2.3
1.2e3
1e23
1_2.3_4e5

# It appears in Range
1..10
Expand Down

0 comments on commit 9d84c54

Please sign in to comment.