diff --git a/lib/yard/parser/ruby/ruby_parser.rb b/lib/yard/parser/ruby/ruby_parser.rb index dd93cb91b..50a4403ef 100644 --- a/lib/yard/parser/ruby/ruby_parser.rb +++ b/lib/yard/parser/ruby/ruby_parser.rb @@ -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 diff --git a/spec/parser/ruby/ruby_parser_spec.rb b/spec/parser/ruby/ruby_parser_spec.rb index bf3f3ff98..d4683d79d 100644 --- a/spec/parser/ruby/ruby_parser_spec.rb +++ b/spec/parser/ruby/ruby_parser_spec.rb @@ -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