From d68cee21437814daa9744a83f32de58eb2a8bb33 Mon Sep 17 00:00:00 2001 From: Code Ass Date: Tue, 22 Aug 2017 14:18:12 +0900 Subject: [PATCH 1/2] Support quoted symbol for JSON-style hash literal Like below: { 'first': 1, "second": 2 } --- lib/rdoc/ruby_lex.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/ruby_lex.rb b/lib/rdoc/ruby_lex.rb index e1124818ac..57c1cc27a2 100644 --- a/lib/rdoc/ruby_lex.rb +++ b/lib/rdoc/ruby_lex.rb @@ -112,6 +112,7 @@ def initialize(content, options) @indent_stack = [] @lex_state = :EXPR_BEG @space_seen = false + @after_question = false @continue = false @line = "" @@ -379,6 +380,8 @@ def token tk = tk1 end end + @after_question = false if @after_question and !(TkQUESTION === tk) + # Tracer.off tk end @@ -593,6 +596,7 @@ def lex_init() |op, io| if @lex_state == :EXPR_END @lex_state = :EXPR_BEG + @after_question = true Token(TkQUESTION) else ch = getc @@ -1359,7 +1363,10 @@ def identify_string(ltype, quoted = ltype, type = nil) end end - if subtype + if peek(0) == ':' and !peek_match?(/^::/) and :EXPR_BEG == @lex_state and !@after_question + str.concat getc + return Token(TkSYMBOL, str) + elsif subtype Token(DLtype2Token[ltype], str) else Token(Ltype2Token[ltype], str) From b57c24174758dbe6579ed58ee0e5ac8b1faaffa6 Mon Sep 17 00:00:00 2001 From: Code Ass Date: Tue, 22 Aug 2017 14:21:13 +0900 Subject: [PATCH 2/2] Add test_class_tokenize_symbol_with_quote --- test/test_rdoc_ruby_lex.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_rdoc_ruby_lex.rb b/test/test_rdoc_ruby_lex.rb index 0eaa871e56..deea2dd2ae 100644 --- a/test/test_rdoc_ruby_lex.rb +++ b/test/test_rdoc_ruby_lex.rb @@ -558,6 +558,36 @@ def test_class_tokenize_symbol assert_equal expected, tokens end + def test_class_tokenize_symbol_with_quote + tokens = RDoc::RubyLex.tokenize <