Skip to content

Handle TkPLUS or TkMINUS and number as TkINTEGER #495

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

Merged
merged 3 commits into from
Aug 22, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ def token
else
tk = tk1
end
elsif (TkPLUS === tk or TkMINUS === tk) and peek(0) =~ /\d/ then
tk1 = token
set_token_position tk.seek, tk.line_no, tk.char_no
tk = Token(tk1.class, tk.text + tk1.text)
end
# Tracer.off
tk
Expand Down
13 changes: 13 additions & 0 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,19 @@ def test_class_tokenize_regexp_escape
assert_equal expected, tokens
end

def test_class_tokenize_number_with_sign_character
tokens = RDoc::RubyLex.tokenize "+3--3r", nil

expected = [
@TK::TkINTEGER .new(0, 1, 0, "+3"),
@TK::TkMINUS .new(2, 1, 2, "-"),
@TK::TkRATIONAL.new(3, 1, 3, "-3r"),
@TK::TkNL .new(6, 1, 6, "\n"),
]

assert_equal expected, tokens
end

def test_class_tokenize_regexp_continuing_backslash
tokens = RDoc::RubyLex.tokenize "/(?<!\\\\)\\n\z/", nil

Expand Down