Skip to content

Commit 6a81c8a

Browse files
authored
Merge pull request #495 from aycabta/handle-plus-minus-and-number
Handle TkPLUS or TkMINUS and number as TkINTEGER
2 parents 956e9d8 + 9d0605e commit 6a81c8a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ def token
378378
else
379379
tk = tk1
380380
end
381+
elsif (TkPLUS === tk or TkMINUS === tk) and peek(0) =~ /\d/ then
382+
tk1 = token
383+
set_token_position tk.seek, tk.line_no, tk.char_no
384+
tk = Token(tk1.class, tk.text + tk1.text)
381385
end
382386
# Tracer.off
383387
tk

test/test_rdoc_ruby_lex.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,19 @@ def test_class_tokenize_regexp_escape
556556
assert_equal expected, tokens
557557
end
558558

559+
def test_class_tokenize_number_with_sign_character
560+
tokens = RDoc::RubyLex.tokenize "+3--3r", nil
561+
562+
expected = [
563+
@TK::TkINTEGER .new(0, 1, 0, "+3"),
564+
@TK::TkMINUS .new(2, 1, 2, "-"),
565+
@TK::TkRATIONAL.new(3, 1, 3, "-3r"),
566+
@TK::TkNL .new(6, 1, 6, "\n"),
567+
]
568+
569+
assert_equal expected, tokens
570+
end
571+
559572
def test_class_tokenize_regexp_continuing_backslash
560573
tokens = RDoc::RubyLex.tokenize "/(?<!\\\\)\\n\z/", nil
561574

0 commit comments

Comments
 (0)