We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f72c753 + 9240e88 commit d566ea1Copy full SHA for d566ea1
lib/rdoc/ruby_lex.rb
@@ -1125,6 +1125,7 @@ def identify_number(op = "")
1125
type = TkINTEGER
1126
allow_point = true
1127
allow_e = true
1128
+ allow_ri = true
1129
non_digit = false
1130
while ch = getc
1131
num << ch
@@ -1154,8 +1155,25 @@ def identify_number(op = "")
1154
1155
num << getc
1156
end
1157
allow_e = false
1158
+ allow_ri = false
1159
allow_point = false
1160
non_digit = ch
1161
+ when allow_ri && "r"
1162
+ if non_digit
1163
+ raise Error, "trailing `#{non_digit}' in number"
1164
+ end
1165
+ type = TkRATIONAL
1166
+ if peek(0) == 'i'
1167
+ type = TkIMAGINARY
1168
+ num << getc
1169
1170
+ break
1171
+ when allow_ri && "i"
1172
+ if non_digit && non_digit != "r"
1173
1174
1175
1176
1177
else
1178
if non_digit
1179
raise Error, "trailing `#{non_digit}' in number"
lib/rdoc/ruby_token.rb
@@ -331,6 +331,8 @@ def Token(token, value = nil)
331
332
[:TkINTEGER, TkVal],
333
[:TkFLOAT, TkVal],
334
+ [:TkRATIONAL, TkVal],
335
+ [:TkIMAGINARY, TkVal],
336
[:TkSTRING, TkVal],
337
[:TkHEREDOC, TkVal],
338
[:TkXSTRING, TkVal],
test/test_rdoc_ruby_lex.rb
@@ -418,5 +418,24 @@ def test_unary_minus
418
assert_equal("-0.1", ruby_lex.token.value)
419
420
421
+ def test_rational_imaginary_tokenize
422
+ tokens = RDoc::RubyLex.tokenize '1.11r + 2.34i + 5.55ri', nil
423
+
424
+ expected = [
425
+ @TK::TkRATIONAL .new( 0, 1, 0, '1.11r'),
426
+ @TK::TkSPACE .new( 5, 1, 5, ' '),
427
+ @TK::TkPLUS .new( 6, 1, 6, '+'),
428
+ @TK::TkSPACE .new( 7, 1, 7, ' '),
429
+ @TK::TkIMAGINARY.new( 8, 1, 8, '2.34i'),
430
+ @TK::TkSPACE .new(13, 1, 13, ' '),
431
+ @TK::TkPLUS .new(14, 1, 14, '+'),
432
+ @TK::TkSPACE .new(15, 1, 15, ' '),
433
+ @TK::TkIMAGINARY.new(16, 1, 16, '5.55ri'),
434
+ @TK::TkNL .new(22, 1, 22, "\n"),
435
+ ]
436
437
+ assert_equal expected, tokens
438
439
440
441
0 commit comments