[Bug #1072] Ripper#filename


#1

Bug #1072: Ripper#filename
http://redmine.ruby-lang.org/issues/show/1072

e$B5/I<<Te(B: Kazuhiro NISHIYAMA
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: ext
Reproducible Version: trunk, ruby -v: ruby 1.9.1p5000 (2009-01-30 trunk
21885) [i686-linux]

Ripper::Filter#filenamee$B$,Dj5A$5$l$F$$$k$N$Ke(BRipper#filenamee$B$,Dj5A$5$l$F$$$J$$$?$a!"e(BNoMethodErrore$B$K$J$j$^$9!#e(B

% cat ~/check_regexp_n.rb
#!/usr/bin/ruby

require ‘ripper/filter’

class CheckRegexpN < Ripper::Filter
def on_regexp_end(token, data)
if /n/ =~ token
puts “#{filename}:#{lineno}:#{column}:#{token}”
end
end
end

ARGV.each do |path|
open(path, “rb”) do |f|
parser = CheckRegexpN.new(f, path)
p [parser.filename, parser.lineno, parser.column]
parser.parse
p [parser.filename, parser.lineno, parser.column]
end
end
% ruby-trunk -vd ~/check_regexp_n.rb lib/minitest/spec.rb
ruby 1.9.1p5000 (2009-01-30 trunk 21885) [i686-linux]
Exception NoMethodError' at .../1.9.1/ripper/filter.rb:27 - undefined methodfilename’ for #Ripper::Lexer:0x8170bbc
…/1.9.1/ripper/filter.rb:27:in filename': undefined methodfilename’
for #Ripper::Lexer:0x8170bbc (NoMethodError)
from …/check_regexp_n.rb:16:in block (2 levels) in <main>' from .../check_regexp_n.rb:14:inopen’
from …/check_regexp_n.rb:14:in block in <main>' from .../check_regexp_n.rb:13:ineach’
from …/check_regexp_n.rb:13:in `’
%

ripper_linenoe$B$r$^$M$7$F0J2<$N$h$&$Ke(Bripper_filenamee$B$rDj5A$7$F$_$?$N$G$9$,!“e(B
if (NIL_P(parser->parsing_thread)) return Qnil;
e$B$N9T$,$”$k$He(Bnile$B$7$+JV$C$F$3$J$+$C$?$N$G%3%a%s%H%"%&%H$7$F$$$^$9!#e(B

Index: parse.y

— parse.y (e$B%j%S%8%g%se(B 21885)
+++ parse.y (e$B:n6H%3%T!<e(B)
@@ -10239,6 +10239,25 @@

/*

  • call-seq:
    • ripper#filename -> String
    • Return current parsing filename.
  • */
    +static VALUE
    +ripper_filename(VALUE self)
    +{
  • struct parser_params *parser;
  • Data_Get_Struct(self, struct parser_params, parser);
  • if (!ripper_initialized_p(parser)) {
  •    rb_raise(rb_eArgError, "method called for uninitialized 
    

object");

  • }
    +/* if (NIL_P(parser->parsing_thread)) return Qnil; */
  • return parser->parser_ruby_sourcefile_string;
    +}

+/*

    • call-seq:
    • ripper#lineno -> Integer
    • Return line number of current parsing line.
      @@ -10288,6 +10307,7 @@
      rb_define_method(Ripper, “initialize”, ripper_initialize, -1);
      rb_define_method(Ripper, “parse”, ripper_parse, 0);
      rb_define_method(Ripper, “column”, ripper_column, 0);
  • rb_define_method(Ripper, “filename”, ripper_filename, 0);
    rb_define_method(Ripper, “lineno”, ripper_lineno, 0);
    rb_define_method(Ripper, “end_seen?”, rb_parser_end_seen_p, 0);
    rb_define_method(Ripper, “encoding”, rb_parser_encoding, 0);

#2

e$B%A%1%C%He(B #1072 e$B$,99?7$5$l$^$7$?!#e(B (by Anonymous)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

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


http://redmine.ruby-lang.org/issues/show/1072


#3

e$B%A%1%C%He(B #1072 e$B$,99?7$5$l$^$7$?!#e(B (by Yui NARUSE)

r25499e$B$,$^$@<h$j9~$^$l$F$$$J$$$h$&$K8+$($^$9e(B

http://redmine.ruby-lang.org/issues/show/1072


#4

e$B%A%1%C%He(B #1072 e$B$,99?7$5$l$^$7$?!#e(B (by Yuki S.)

e$B%9%F!<%?%9e(B Assignede$B$+$ie(BClosede$B$KJQ99e(B

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


http://redmine.ruby-lang.org/issues/show/1072