Skip to content

Fix "!" after constant handling, it's identifier #482

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 2 commits into from
Aug 8, 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
6 changes: 5 additions & 1 deletion lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,11 @@ def identify_identifier
end

if token[0, 1] =~ /[A-Z]/
return Token(TkCONSTANT, token)
if token[-1] =~ /[!?]/
return Token(TkIDENTIFIER, token)
else
return Token(TkCONSTANT, token)
end
elsif token[token.size - 1, 1] =~ /[!?]/
return Token(TkFID, token)
else
Expand Down
16 changes: 16 additions & 0 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,5 +523,21 @@ def test_class_tokenize_square_bracket_as_method
assert_equal expected, tokens
end

def test_class_tokenize_constant_with_exclamation
tokens = RDoc::RubyLex.tokenize "Hello there, Dave!", nil

expected = [
@TK::TkCONSTANT .new( 0, 1, 0, "Hello"),
@TK::TkSPACE .new( 5, 1, 5, " "),
@TK::TkIDENTIFIER.new( 6, 1, 6, "there"),
@TK::TkCOMMA .new(11, 1, 11, ","),
@TK::TkSPACE .new(12, 1, 12, " "),
@TK::TkIDENTIFIER.new(13, 1, 13, "Dave!"),
@TK::TkNL .new(18, 1, 18, "\n")
]

assert_equal expected, tokens
end

end