Skip to content
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

Fix JSON-style Hash literal for args of method #511

Merged
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: 4 additions & 2 deletions lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1380,16 +1380,18 @@ def identify_string(ltype, quoted = ltype, type = nil)

if peek(0) == ':' and !peek_match?(/^::/) and :EXPR_BEG == @lex_state and !@after_question
str.concat getc
return Token(TkSYMBOL, str)
@lex_state = :EXPR_ARG if peek_match?(/\s*:/)
Token(TkSYMBOL, str)
elsif subtype
@lex_state = :EXPR_END
Token(DLtype2Token[ltype], str)
else
@lex_state = :EXPR_END
Token(Ltype2Token[ltype], str)
end
ensure
@ltype = nil
@quoted = nil
@lex_state = :EXPR_END
end
end

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 @@ -927,6 +927,22 @@ def test_class_tokenize_symbol
assert_equal expected, tokens
end

def test_class_tokenize_symbol_for_method
tokens = RDoc::RubyLex.tokenize 'meth("key": :val)', nil

expected = [
@TK::TkIDENTIFIER.new( 0, 1, 0, 'meth'),
@TK::TkLPAREN .new( 4, 1, 4, '('),
@TK::TkSYMBOL .new( 5, 1, 5, '"key":'),
@TK::TkSPACE .new(11, 1, 11, ' '),
@TK::TkSYMBOL .new(12, 1, 12, ':val'),
@TK::TkRPAREN .new(16, 1, 16, ')'),
@TK::TkNL .new(17, 1, 17, "\n"),
]

assert_equal expected, tokens
end

def test_class_tokenize_particular_kind_of_symbols
tokens = RDoc::RubyLex.tokenize '{ Thomas: :Thomas, Dave!: :Dave!, undef: :undef }', nil

Expand Down