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

fix number literals in the Ruby lexer #1456

Merged
merged 2 commits into from
Mar 8, 2020
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
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