Skip to content

Commit

Permalink
Fix parsing of symbols when symbol is a keyword
Browse files Browse the repository at this point in the history
Fixes #1170
  • Loading branch information
lsegal committed Jun 3, 2018
1 parent 5321e10 commit cd4452b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 3 additions & 11 deletions lib/yard/parser/ruby/ruby_parser.rb
Expand Up @@ -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]]

Expand Down
3 changes: 2 additions & 1 deletion spec/parser/ruby/ruby_parser_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit cd4452b

Please sign in to comment.