Charles Oliver Nutter wrote: > Werner Schuster (murphee) wrote: > >> Charles Oliver Nutter wrote: >> >> This will allow to use jparsetree for static analysis tools (or >> generally, tools that look at Ruby source code), since these need proper >> source range information. >> > This looks pretty nice. Do you think that there's a potential to ad > enough information to the parse tree for an IDE, for example? Or does > parsetree provide too little? > What else do you need? Potentially you could throw in everything you want (the approach of mixing in Modules allows to treat the nested lists as an annotated/annotateable AST).
Hm... one thing I can think of would be comments, which don't really fit into the AST. I guess I could add some method to get the comments (maybe as [:comment, "text"] or something like this). The original ParseTree doesn't have this; BTW: how's your Japanese: Matz (or someone using his name) made this comment: http://www.rubyist.net/~matz/20070419.html#p03 about my article about Ruby and it's AST: http://jroller.com/page/murphee?entry=ruby_let_s_get_an I don't see this ripper tool mentioned; > I also assume we're not particularly interested in performance at this > point...I can't imagine mixing that module into every sexp to be a > performance win... > Well... jparsetree isn't really a sprinter - parsing jparsetree.rb takes 5 seconds on my machine. I have an idea to speed this up: - use jparsetree on itself, then - use my fancy pants pattern matching tools to compile it into Java code Since jparsetree is mostly just calls from/to Java methods, this should work out nicely. I have the beginnings of this, but it's not done. As for speed of mixins: how costly is that? > Ok, I'm willing to help, but you're gonna need to give me a primer on > what you need. From what I can gather you need a way to get at the AST > for methods that are define_method'ed from other methods, yes? And is > the issue that you can't find how to get at the AST? > Yes; look at the lib/runtimeAstProvider.rb file; I found ways to get at the AST Node for a few types of methods, but not for all (Caution: the code in this file is really not pretty). Basically, I use a reflection trick that opens the Method class and uses reflection to get the Node variable of the Method object; The problem is that there are many types of methods at runtime. The ParseTree test suite uses this class: class Examples attr_reader :reader attr_writer :writer def a_method; 1+1; end alias an_alias a_method def self.bmethod_maker define_method(:bmethod_added) do |x| x + 1 end end ·· def self.dmethod_maker define_method :dmethod_added, self.method(:bmethod_maker) end· ·· self.bmethod_maker self.dmethod_maker· # dmethod_maker if RUBY_VERSION < "1.9" end You can use this code to get the AST for a method: actual = ParseTree.new(false).parse_tree_for_method(Examples,method_name) The test suite tries to get: :writer= :bmethod_added :dmethod_added :an_alias :reader This still fails for bmethod, dmethod, and ivar; I used some hacks to get the accessors (the ones added with attr_accessor); The lib/runtimeAstProvider.rb file contains some of the ways I found to get at the AST Nodes for the methods, but - it's really ugly, unmaintainable code (the result of a few days of cursing and and trial/error) - it'd be easier to have something like getASTNode for all methods; murphee _______________________________________________ Jruby-extras-devel mailing list [email protected] http://rubyforge.org/mailman/listinfo/jruby-extras-devel
