Project

General

Profile

Actions

Backport #7255

closed

Ripper inside class_eval ommits :string_content between new line and :string_embexpr

Added by brueckenschlaeger23 (Micha J) over 11 years ago. Updated over 11 years ago.

Status:
Closed
[ruby-core:48703]

Description

See the following Code parsed by Ripper using

content = 'class_eval <<-RUBY, __FILE__, __LINE__+1        
    
    def #{parent}contents(*args)
      ""
    end
RUBY
'

Ripper::SexpBuilder.new(content).parse

The resulting sexp ommits truncates the first string_add to " \n" instead of " \n def "

        - - :string_literal
          - - :string_add
            - - :string_add
              - - :string_add
                - - :string_content
                - - :@tstring_content
                  - "        \n"
                  - - 2
                    - 0

If you remove the empty line, it works fine and the " def " is part of the string. As well it works without any embed #{}.

Updated by brueckenschlaeger23 (Micha J) over 11 years ago

I noticed, that this bug reaches a bit wider:

'class_eval <<-RUBY, __FILE__, __LINE__+1        
    
    def #{parent}_contents(*args)
      test = ""
      test ||= "#{parent}" 
    end
RUBY
'

' test ||= "' also is omitted by ripper. This is the string between the "\n" of [:@tstring_content, "_contents(*args)\n test = ""\n", [3, 21]]] and the next embed.

Updated by brueckenschlaeger23 (Micha J) over 11 years ago

Another update: It's not connected to class_eval but to the <<-RUBY and <<RUBY multiline String versions. This is my only use case for this format so I didn't notice.

Updated by brueckenschlaeger23 (Micha J) over 11 years ago

I did some further digging regarding the parser/scanner events.

Basically the cause for the error can be seen here (parsing the example from the description).

[:@ident, "class_eval", [1, 0]]
[:@sp, " ", [1, 10]]
[:@heredoc_beg, "<<-RUBY", [1, 11]]
[:string_content]
[:@tstring_content, "        \n", [2, 0]]
[:string_add, [:string_content], [:@tstring_content, "        \n", [2, 0]]]
[:@embexpr_beg, "        def \#{", [3, 0]]   <------- this line
...

The scanner-event :@embexpr_beg contains the missing text which then will be discarded to create the string_embexp from the sexp.

Updated by zzak (zzak _) over 11 years ago

  • Category set to ext
  • Assignee set to nobu (Nobuyoshi Nakada)
Actions #5

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38235.
Micha, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


parse.y: flush string content

  • parse.y (parser_here_document): flush string content between new
    line and :string_embexpr. [ruby-core:48703] [Bug #7255]
Actions #6

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport193
  • Category deleted (ext)
  • Status changed from Closed to Assigned
  • Assignee changed from nobu (Nobuyoshi Nakada) to usa (Usaku NAKAMURA)
Actions #7

Updated by usa (Usaku NAKAMURA) over 11 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r38319.
Micha, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 38235: [Backport #7255]

* parse.y (parser_here_document): flush string content between new
  line and :string_embexpr.  [ruby-core:48703] [Bug #7255]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0