Skip to content

Commit 0c5eb20

Browse files
authored
Merge pull request #511 from aycabta/fix-json-style-hash-literal-for-args-of-method
Fix JSON-style Hash literal for args of method
2 parents fe44516 + a2c9282 commit 0c5eb20

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/rdoc/ruby_lex.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,16 +1380,18 @@ def identify_string(ltype, quoted = ltype, type = nil)
13801380

13811381
if peek(0) == ':' and !peek_match?(/^::/) and :EXPR_BEG == @lex_state and !@after_question
13821382
str.concat getc
1383-
return Token(TkSYMBOL, str)
1383+
@lex_state = :EXPR_ARG if peek_match?(/\s*:/)
1384+
Token(TkSYMBOL, str)
13841385
elsif subtype
1386+
@lex_state = :EXPR_END
13851387
Token(DLtype2Token[ltype], str)
13861388
else
1389+
@lex_state = :EXPR_END
13871390
Token(Ltype2Token[ltype], str)
13881391
end
13891392
ensure
13901393
@ltype = nil
13911394
@quoted = nil
1392-
@lex_state = :EXPR_END
13931395
end
13941396
end
13951397

test/test_rdoc_ruby_lex.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,22 @@ def test_class_tokenize_symbol
927927
assert_equal expected, tokens
928928
end
929929

930+
def test_class_tokenize_symbol_for_method
931+
tokens = RDoc::RubyLex.tokenize 'meth("key": :val)', nil
932+
933+
expected = [
934+
@TK::TkIDENTIFIER.new( 0, 1, 0, 'meth'),
935+
@TK::TkLPAREN .new( 4, 1, 4, '('),
936+
@TK::TkSYMBOL .new( 5, 1, 5, '"key":'),
937+
@TK::TkSPACE .new(11, 1, 11, ' '),
938+
@TK::TkSYMBOL .new(12, 1, 12, ':val'),
939+
@TK::TkRPAREN .new(16, 1, 16, ')'),
940+
@TK::TkNL .new(17, 1, 17, "\n"),
941+
]
942+
943+
assert_equal expected, tokens
944+
end
945+
930946
def test_class_tokenize_particular_kind_of_symbols
931947
tokens = RDoc::RubyLex.tokenize '{ Thomas: :Thomas, Dave!: :Dave!, undef: :undef }', nil
932948

0 commit comments

Comments
 (0)