Hi guys, For a project I want to be able to get access to the block definition as a string. After some help I came up with this: http://gist.github.com/279656 This solves the problem. When I run the same code on top of IronRuby, I get the following error message: /Users/Ben/Library/ironruby-0.9.3/lib/ironruby/gems/1.8/gems/ParseTree-3.0.4/lib/parse_tree_extensions.rb:52:in `to_sexp'': undefined method `parse_tree_for_proc'' for #<ParseTree:0x0000726 @include_newlines=false> (NoMethodError) from /Users/Ben/Library/ironruby-0.9.3/lib/ironruby/gems/1.8/gems/ParseTree-3.0.4/lib/parse_tree_extensions.rb:57:in `to_ruby'' from mock.rb:31:in `block_as_string'' from mock.rb:34 Any ideas on this? It''s using Ruby2Ruby and ParseTree. Is it because it''s based around C extensions? Anyone know how to do it on the CLR? Thanks Ben
Jimmy Schementi
2010-Jan-18 02:32 UTC
[Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby
> Any ideas on this? It''s using Ruby2Ruby and ParseTree. Is it because it''s > based around C extensions? Anyone know how to do it on the CLR?http://parsetree.rubyforge.org/ ParseTree hooks into MRI''s internals and exposes the parse tree for a given chunk of Ruby code. For this to work on IronRuby you''d have to rewrite the C-extension-portion of this library to look at the DLR trees (may require changes to ironruby as well to expose the tree, but I''m not sure). Ruby2Ruby is just a Ruby parser written in Ruby, but depends on racc, which uses a C extension, though it seems like you can run racc without it. ~Jimmy
Michael Letterle
2010-Jan-18 03:00 UTC
[Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby
Considering we have access to the AST.. I would think that.. in theory at least, it would be EASIER to implement than CRuby... But yeah, what Jimmy said :) On Sun, Jan 17, 2010 at 9:32 PM, Jimmy Schementi < Jimmy.Schementi at microsoft.com> wrote:> > Any ideas on this? It''s using Ruby2Ruby and ParseTree. Is it because it''s > > based around C extensions? Anyone know how to do it on the CLR? > > http://parsetree.rubyforge.org/ > > ParseTree hooks into MRI''s internals and exposes the parse tree for a given > chunk of Ruby code. For this to work on IronRuby you''d have to rewrite the > C-extension-portion of this library to look at the DLR trees (may require > changes to ironruby as well to expose the tree, but I''m not sure). > > Ruby2Ruby is just a Ruby parser written in Ruby, but depends on racc, which > uses a C extension, though it seems like you can run racc without it. > > ~Jimmy > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-- Michael Letterle IronRuby MVP http://blog.prokrams.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100117/40faf560/attachment-0001.html>
Jim Deville
2010-Jan-18 05:25 UTC
[Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby
ParseTree is actually already implemented for IronRuby. Tomas did that to get merb running last year. Ruby2Ruby will probably need some work though. ________________________________ From: Michael Letterle <michael.letterle at gmail.com> Sent: Sunday, January 17, 2010 7:01 PM To: ironruby-core at rubyforge.org <ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby Considering we have access to the AST.. I would think that.. in theory at least, it would be EASIER to implement than CRuby... But yeah, what Jimmy said :) On Sun, Jan 17, 2010 at 9:32 PM, Jimmy Schementi <Jimmy.Schementi at microsoft.com<mailto:Jimmy.Schementi at microsoft.com>> wrote:> Any ideas on this? It''s using Ruby2Ruby and ParseTree. Is it because it''s > based around C extensions? Anyone know how to do it on the CLR?http://parsetree.rubyforge.org/ ParseTree hooks into MRI''s internals and exposes the parse tree for a given chunk of Ruby code. For this to work on IronRuby you''d have to rewrite the C-extension-portion of this library to look at the DLR trees (may require changes to ironruby as well to expose the tree, but I''m not sure). Ruby2Ruby is just a Ruby parser written in Ruby, but depends on racc, which uses a C extension, though it seems like you can run racc without it. ~Jimmy _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Michael Letterle IronRuby MVP http://blog.prokrams.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100118/29e5ec11/attachment.html>
Tomas Matousek
2010-Jan-18 06:08 UTC
[Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby
Yes, the base ParseTree functionality is implemented in Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\ParseTree\IronRubyParseTreeOps.cs and Merlin\Main\Languages\Ruby\Libs\parse_tree.rb. It''s not well tested code so it might be missing something or not exactly emulate Ruby''s behavior (it''s somewhat difficult to figure out how the tree should look like for some syntax elements). So, please, file a bug if you fined differences that matter. We also accept unit test contributions in a form of a spec :). IronRuby 0.9.3.0 on .NET 2.0.50727.4927 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''parse_tree''=> true>>> ParseTree.translate("puts ''hello''")=> [:fcall, :puts, [:array, [:str, "hello"]]] You can get a parse tree for a string and for a method. So far blocks are not supported. Do blocks work in Ruby 1.8.6? Note that the ability to retrieve a parse tree for an arbitrary method or a block makes all apps more memory consuming and thus also slower. Ruby trees of every single method and block need to stay in the memory for the case someone might call ParseTree.translate on them. We might need to do something about that for v1.0. Ideally, there would be a syntax in Ruby to define a quoted block or a method - that is a syntax that takes a method or block declaration and turns it into a parse tree. Something like ParseTree.translate but with a real code instead of a string. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Sunday, January 17, 2010 9:26 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby ParseTree is actually already implemented for IronRuby. Tomas did that to get merb running last year. Ruby2Ruby will probably need some work though. ________________________________ From: Michael Letterle <michael.letterle at gmail.com> Sent: Sunday, January 17, 2010 7:01 PM To: ironruby-core at rubyforge.org <ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] Bug?: Ruby2Ruby and ParseTree on IronRuby Considering we have access to the AST.. I would think that.. in theory at least, it would be EASIER to implement than CRuby... But yeah, what Jimmy said :) On Sun, Jan 17, 2010 at 9:32 PM, Jimmy Schementi <Jimmy.Schementi at microsoft.com<mailto:Jimmy.Schementi at microsoft.com>> wrote:> Any ideas on this? It''s using Ruby2Ruby and ParseTree. Is it because it''s > based around C extensions? Anyone know how to do it on the CLR?http://parsetree.rubyforge.org/ ParseTree hooks into MRI''s internals and exposes the parse tree for a given chunk of Ruby code. For this to work on IronRuby you''d have to rewrite the C-extension-portion of this library to look at the DLR trees (may require changes to ironruby as well to expose the tree, but I''m not sure). Ruby2Ruby is just a Ruby parser written in Ruby, but depends on racc, which uses a C extension, though it seems like you can run racc without it. ~Jimmy _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Michael Letterle IronRuby MVP http://blog.prokrams.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100118/d885a1a1/attachment.html>