Bug #4543

Ripperで"<<-eos\neos"を正常にパースできない

Added by Kazunori SAKAMOTO about 3 years ago. Updated almost 3 years ago.

[ruby-dev:<unknown>]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
Category:ext
Target version:1.9.3
ruby -v:ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] Backport:

Description

=begin
Ripper::SexpBuilder.new(%Q!<<-eos\neos!).parse
にて、onheredocend メソッドが呼び出されません。

■検証済みバージョン
ruby 1.9.3dev (2011-03-31 trunk 31223) [i686-linux]
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
ruby 1.9.1p431 (2011-02-18 revision 30908) [i686-linux]

■検証用スクリプト
require 'ripper'

class Parser < Ripper::SexpBuilder
ms = Ripper::SexpBuilder.new('').methods
defs = ms.map { |s| s.tos }
.select { |s| s.start
with?('on_') }
.map { |s| %Q{
def #{s}(*args)
print '#{s}: '
p args
end
}}.join
eval(defs)
end

def parse(src)
puts "*" + src.inspect + "*"
Parser.new(src).parse
puts
end

parse(%Q!<<-eos\neos!)
parse(%Q!<<-eos\n\neos!)

■実行結果
*"<<-eos\neos"*
onheredocbeg: ["<<-eos"]
onstringcontent: []
onstringliteral: [[]]
onnl: ["\n"]
on
stmtsnew: []
on
stmtsadd: [[], [[]]]
on
program: [[[], [[]]]]

*"<<-eos\n\neos"*
onheredocbeg: ["<<-eos"]
onstringcontent: []
ontstringcontent: ["\n"]
onheredocend: ["eos"]
onstringadd: [[], ["\n"]]
onstringliteral: [[[], ["\n"]]]
onnl: ["\n"]
on
stmtsnew: []
on
stmtsadd: [[], [[[], ["\n"]]]]
on
program: [[[], [[[], ["\n"]]]]]
=end

History

#1 Updated by Kazunori SAKAMOTO about 3 years ago

=begin
----"<<-eos\neos"----
onheredocbeg: ["<<-eos"]
onstringcontent: []
onstringliteral: [[]]
onnl: ["\n"]
on
stmtsnew: []
on
stmtsadd: [[], [[]]]
on
program: [[[], [[]]]]

----"<<-eos\n\neos----
onheredocbeg: ["<<-eos"]
onstringcontent: []
ontstringcontent: ["\n"]
onheredocend: ["eos"]
onstringadd: [[], ["\n"]]
onstringliteral: [[[], ["\n"]]]
onnl: ["\n"]
on
stmtsnew: []
on
stmtsadd: [[], [[[], ["\n"]]]]
on
program: [[[], [[[], ["\n"]]]]]

=end

#2 Updated by Kazunori SAKAMOTO about 3 years ago

=begin
require 'ripper'

class Parser < Ripper::SexpBuilder
ms = Ripper::SexpBuilder.new('').methods
defs = ms.map { |s| s.tos }
.select { |s| s.start
with?('on_') }
.map { |s| %Q{
def #{s}(*args)
print '#{s}: '
p args
end
}}.join
eval(defs)
end

def parse(src)
puts "*" + src.inspect + "*"
Parser.new(src).parse
puts
end

parse(%Q!<<-eos\neos!)
parse(%Q!<<-eos\n\neos!)

すいません、整形したものを貼り直します。
=end

#3 Updated by Koichi Sasada almost 3 years ago

  • Category set to ext
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada

#4 Updated by Hiroshi Nakamura almost 3 years ago

  • Target version set to 1.9.3

#5 Updated by Nobuyoshi Nakada almost 3 years ago

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

r32412で修正しました。

Also available in: Atom PDF