Skip to content

Commit 5544853

Browse files
committed
Tokenize out-of-place reserved words as identifiers
1 parent 24efb01 commit 5544853

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

History.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Noria.
88
* Fixed tokenization of % when it is not followed by a $-string type
99
* Fixed display of __END__ in documentation examples in HTML output
10+
* Fixed tokenization of reserved words used as new-style hash keys
1011

1112

1213
=== 3.12.1 / 2013-02-05

lib/rdoc/ruby_lex.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,8 @@ def identify_identifier
936936
@indent += 1
937937
@indent_stack.push token_c
938938
end
939+
else
940+
token_c = TkIDENTIFIER
939941
end
940942

941943
elsif DEINDENT_CLAUSE.include?(token)

test/test_rdoc_ruby_lex.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ def x
7777
assert_equal expected, tokens
7878
end
7979

80+
def test_class_tokenize_hash_symbol
81+
tokens = RDoc::RubyLex.tokenize '{ class:"foo" }', nil
82+
83+
expected = [
84+
@TK::TkLBRACE .new( 0, 1, 0, '{'),
85+
@TK::TkSPACE .new( 1, 1, 1, ' '),
86+
@TK::TkIDENTIFIER.new( 2, 1, 2, 'class'),
87+
@TK::TkSYMBEG .new( 7, 1, 7, ':'),
88+
@TK::TkSTRING .new( 8, 1, 8, '"foo"'),
89+
@TK::TkSPACE .new(13, 1, 13, ' '),
90+
@TK::TkRBRACE .new(14, 1, 14, '}'),
91+
@TK::TkNL .new(15, 1, 15, "\n"),
92+
]
93+
94+
assert_equal expected, tokens
95+
end
96+
8097
def test_class_tokenize_heredoc_indent
8198
tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
8299
string = <<-STRING

0 commit comments

Comments
 (0)