Skip to content

Commit bb8b2d4

Browse files
authored
Fix colorization of imaginary/rational numbers (ruby#1733)
In prism there is no singualr `RATIONAL`/`IMAGINARY` token. Instead they are more fine-grained.
1 parent 1ae9dc1 commit bb8b2d4

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

lib/rdoc/parser/ruby_colorizer.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ module RDoc::Parser::RubyColorizer
3434
CONSTANT: :constant,
3535
LABEL: :value,
3636
INTEGER: :value,
37+
INTEGER_IMAGINARY: :value,
38+
INTEGER_RATIONAL: :value,
39+
INTEGER_RATIONAL_IMAGINARY: :value,
3740
FLOAT: :value,
38-
RATIONAL: :value,
39-
IMAGINARY: :value,
41+
FLOAT_IMAGINARY: :value,
42+
FLOAT_RATIONAL: :value,
43+
FLOAT_RATIONAL_IMAGINARY: :value,
4044
COMMENT: :comment,
4145
EMBDOC_BEGIN: :comment,
4246
EMBDOC_LINE: :comment,

test/rdoc/parser/ruby_colorizer_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,25 @@ def f
199199
assert_include(tokens, token(:string, '}'))
200200
assert_include(tokens, token(:string, " heredoc\n"))
201201
end
202+
203+
def test_rational_imaginary
204+
code = <<~RUBY
205+
2i
206+
2r
207+
2ri
208+
209+
2.0i
210+
2.0r
211+
2.0ri
212+
RUBY
213+
tokens = RDoc::Parser::RubyColorizer.colorize(code)
214+
assert_equal(code, tokens.map(&:text).join)
215+
216+
assert_include(tokens, token(:value, "2i"))
217+
assert_include(tokens, token(:value, "2r"))
218+
assert_include(tokens, token(:value, "2ri"))
219+
assert_include(tokens, token(:value, "2.0i"))
220+
assert_include(tokens, token(:value, "2.0r"))
221+
assert_include(tokens, token(:value, "2.0ri"))
222+
end
202223
end

0 commit comments

Comments
 (0)