From cd4452bf104b088e3007ec94f477274a3bdc81a2 Mon Sep 17 00:00:00 2001 From: Loren Segal Date: Sat, 2 Jun 2018 18:40:03 -0700 Subject: [PATCH] Fix parsing of symbols when symbol is a keyword Fixes #1170 --- lib/yard/parser/ruby/ruby_parser.rb | 14 +++----------- spec/parser/ruby/ruby_parser_spec.rb | 3 ++- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/yard/parser/ruby/ruby_parser.rb b/lib/yard/parser/ruby/ruby_parser.rb index 845947011..8a189e87b 100644 --- a/lib/yard/parser/ruby/ruby_parser.rb +++ b/lib/yard/parser/ruby/ruby_parser.rb @@ -282,17 +282,9 @@ def add_token(token, data) end end - if token == :symbeg - @symbol = [:symbol, data, [lineno, charno]] - elsif @symbol - case token - when :tstring_content - @symbol[1] += data - when :tstring_end, :const, :ident - @symbol[1] += data - @tokens << @symbol - @symbol = nil - end + if @tokens.last && (@tokens.last[0] == :symbeg || + (@tokens.last[0] == :symbol && token.to_s =~ /^tstring/)) + @tokens[-1] = [:symbol, @tokens.last[1] + data, @tokens.last[2]] elsif @heredoc_state == :started @heredoc_tokens << [token, data, [lineno, charno]] diff --git a/spec/parser/ruby/ruby_parser_spec.rb b/spec/parser/ruby/ruby_parser_spec.rb index d0e061efa..2ba9006f8 100644 --- a/spec/parser/ruby/ruby_parser_spec.rb +++ b/spec/parser/ruby/ruby_parser_spec.rb @@ -310,10 +310,11 @@ class X Fuu = :bar Bar = :BAR Baz = :"B+z" + Qux = :if end eof symbols = tokens.select {|t| t[0] == :symbol }.map {|t| t[1] } - expect(symbols).to eq %w(:'' :bar :BAR :"B+z") + expect(symbols).to eq %w(:'' :bar :BAR :"B+z" :if) end it "parses %w() array in constant declaration" do