Project

General

Profile

This project is closed and read-only.

Actions

Backport #7255

closed

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

Backport #7255: Ripper inside class_eval ommits :string_content between new line and :string_embexpr

Added by brueckenschlaeger23 (Micha J) almost 14 years ago. Updated almost 14 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) almost 14 years ago Actions #1 [ruby-core:48704]

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) almost 14 years ago Actions #2 [ruby-core:48705]

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) almost 14 years ago Actions #3 [ruby-core:48892]

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 _) almost 14 years ago Actions #4 [ruby-core:48936]

  • Category set to ext
  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by nobu (Nobuyoshi Nakada) almost 14 years ago Actions #5

  • 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]

Updated by nobu (Nobuyoshi Nakada) almost 14 years ago Actions #6

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

Updated by usa (Usaku NAKAMURA) almost 14 years ago Actions #7

  • 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: PDF Atom