Skip to content

Commit

Permalink
Tokenize out-of-place reserved words as identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Feb 24, 2013
1 parent 24efb01 commit 5544853
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Noria.
* Fixed tokenization of % when it is not followed by a $-string type
* Fixed display of __END__ in documentation examples in HTML output
* Fixed tokenization of reserved words used as new-style hash keys


=== 3.12.1 / 2013-02-05
Expand Down
2 changes: 2 additions & 0 deletions lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ def identify_identifier
@indent += 1
@indent_stack.push token_c
end
else
token_c = TkIDENTIFIER
end

elsif DEINDENT_CLAUSE.include?(token)
Expand Down
17 changes: 17 additions & 0 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ def x
assert_equal expected, tokens
end

def test_class_tokenize_hash_symbol
tokens = RDoc::RubyLex.tokenize '{ class:"foo" }', nil

expected = [
@TK::TkLBRACE .new( 0, 1, 0, '{'),
@TK::TkSPACE .new( 1, 1, 1, ' '),
@TK::TkIDENTIFIER.new( 2, 1, 2, 'class'),
@TK::TkSYMBEG .new( 7, 1, 7, ':'),
@TK::TkSTRING .new( 8, 1, 8, '"foo"'),
@TK::TkSPACE .new(13, 1, 13, ' '),
@TK::TkRBRACE .new(14, 1, 14, '}'),
@TK::TkNL .new(15, 1, 15, "\n"),
]

assert_equal expected, tokens
end

def test_class_tokenize_heredoc_indent
tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
string = <<-STRING
Expand Down

0 comments on commit 5544853

Please sign in to comment.