Skip to content

Commit

Permalink
Fix a bug in Ripper that causes string_content tokens with newlines t…
Browse files Browse the repository at this point in the history
…o only

show the last line as a token in the AST.
  • Loading branch information
lsegal committed Feb 26, 2011
1 parent bdd8a8f commit bd35156
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/yard/parser/ruby/ruby_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ def on_qwords_new

def on_string_literal(*args)
node = visit_event_arr(AstNode.new(:string_literal, args))
if @source[charno, 1] !~ /["']/
nsr = node.source_range
node.source_range = Range.new(nsr.first, nsr.last + 1)
if args.size == 1
r = args[0].source_range
if node.source_range != Range.new(r.first - 1, r.last + 1)
klass = AstNode.node_class_for(node[0].type)
r = Range.new(node.source_range.first + 1, node.source_range.last - 1)
node[0] = klass.new(node[0].type, [@source[r]], :line => node.line_range, :char => r)
end
end
node
end
Expand Down
4 changes: 4 additions & 0 deletions spec/parser/ruby/ruby_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ def method2; end
["'", '"'].each do |q|
src = "#{q}hello\n\nworld#{q}"
s = stmt(src)
s.jump(:string_content)[0].should == "hello\n\nworld"
s.source.should == src
end

src = '("this is a string")'
stmt(src).jump(:string_literal).source.should == '"this is a string"'
end
end
end if HAVE_RIPPER

0 comments on commit bd35156

Please sign in to comment.