Skip to content

Commit 4acef28

Browse files
authored
Merge pull request #482 from aycabta/fix-exclamation-after-constant
Fix "!" after constant handling, it's identifier
2 parents 27f129e + 4d29fbf commit 4acef28

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,11 @@ def identify_identifier
10561056
end
10571057

10581058
if token[0, 1] =~ /[A-Z]/
1059-
return Token(TkCONSTANT, token)
1059+
if token[-1] =~ /[!?]/
1060+
return Token(TkIDENTIFIER, token)
1061+
else
1062+
return Token(TkCONSTANT, token)
1063+
end
10601064
elsif token[token.size - 1, 1] =~ /[!?]/
10611065
return Token(TkFID, token)
10621066
else

test/test_rdoc_ruby_lex.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,5 +553,21 @@ def test_class_tokenize_square_bracket_as_method
553553
assert_equal expected, tokens
554554
end
555555

556+
def test_class_tokenize_constant_with_exclamation
557+
tokens = RDoc::RubyLex.tokenize "Hello there, Dave!", nil
558+
559+
expected = [
560+
@TK::TkCONSTANT .new( 0, 1, 0, "Hello"),
561+
@TK::TkSPACE .new( 5, 1, 5, " "),
562+
@TK::TkIDENTIFIER.new( 6, 1, 6, "there"),
563+
@TK::TkCOMMA .new(11, 1, 11, ","),
564+
@TK::TkSPACE .new(12, 1, 12, " "),
565+
@TK::TkIDENTIFIER.new(13, 1, 13, "Dave!"),
566+
@TK::TkNL .new(18, 1, 18, "\n")
567+
]
568+
569+
assert_equal expected, tokens
570+
end
571+
556572
end
557573

0 commit comments

Comments
 (0)