Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Kind of ParsTree for 1.9.1

Reply
Thread Tools

Kind of ParsTree for 1.9.1

 
 
Macario Ortega
Guest
Posts: n/a
 
      08-04-2009


Hi, I've been missing ParseTree very badly in 1.9.1. So in my naivité I
decided to try to convert YARV iseq's to Sexp's similar of those
produced by ParseTree. So far I can convert simple expressions, method
calls, nested method calls, arrays, hashes, I can extract method
parameter and default values provided the expression is not too
complicated.
At first it seemed easy until I hitted control structures.

Is someone aware of a similar effort?

Does anyone else craves AST manipulation in 1.9.1 as bad as me?

Anyone care to join?

Any sugested reads appart from YARV wiki?

My attempt is hosted at http://github.com/maca/iseq_parser/tree/master


Thanks
Macario
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Thomas Chust
Guest
Posts: n/a
 
      08-04-2009
2009/8/4 Macario Ortega <(E-Mail Removed)>:
> [...]
> Hi, I've been missing ParseTree very badly in 1.9.1. So in my naivit=E9 I
> decided to try to convert YARV iseq's to Sexp's similar of those
> produced by ParseTree.
> [...]
> Is someone aware of a similar effort?
> [...]


Hello,

the Ruby 1.9.1p243 that I installed from source came with a library
called 'ripper' that can produce S-expression parse trees from Ruby
code, like this:

$ cat foo.rb
require 'ripper'
require 'pp'

pp Ripper.sexp %{
def foo
:bar
end
}

$ ruby foo.rb
[rogram,
[[:def,
[:@ident, "foo", [2, 6]],
[arams, nil, nil, nil, nil, nil],
[:body_stmt,
[[:symbol_literal, [:symbol, [:@ident, "bar", [3, 5]]]]],
nil,
nil,
nil]]]]

I played around with that a little, but didn't try to code anything
serious. Also, since I'm new to Ruby and haven't used ParseTree
before, I don't know how compatible the abstract syntax tree
representations are.

cu,
Thomas


--=20
When C++ is your hammer, every problem looks like your thumb.

 
Reply With Quote
 
 
 
 
Caleb Clausen
Guest
Posts: n/a
 
      08-04-2009
On 8/4/09, Thomas Chust <(E-Mail Removed)> wrote:
> the Ruby 1.9.1p243 that I installed from source came with a library
> called 'ripper' that can produce S-expression parse trees from Ruby
> code, like this:
>
> $ cat foo.rb
> require 'ripper'
> require 'pp'
>
> pp Ripper.sexp %{
> def foo
> :bar
> end
> }


Hey, I've been wondering how one gets a tree out of ripper, or even if
it can be done at all. Thanks!

> $ ruby foo.rb
> [rogram,
> [[:def,
> [:@ident, "foo", [2, 6]],
> [arams, nil, nil, nil, nil, nil],
> [:body_stmt,
> [[:symbol_literal, [:symbol, [:@ident, "bar", [3, 5]]]]],
> nil,
> nil,
> nil]]]]
>
> I played around with that a little, but didn't try to code anything
> serious. Also, since I'm new to Ruby and haven't used ParseTree
> before, I don't know how compatible the abstract syntax tree
> representations are.


That's definitely not compatible with any of the ParseTree formats.

 
Reply With Quote
 
Macario Ortega
Guest
Posts: n/a
 
      08-04-2009

Thomas, Thanks for you reply. I wish there was more info on ripper,
definitelly useful Allthough nice thing about ParseTree is that it
works with "live" objects, meanining there is no need to resort to the
source you can extract the AST for a Class even it was defined with eval
or redefined later.



Thomas Chust wrote:
> 2009/8/4 Macario Ortega <(E-Mail Removed)>:
>> [...]
>> Hi, I've been missing ParseTree very badly in 1.9.1. So in my naivit� I
>> decided to try to convert YARV iseq's to Sexp's similar of those
>> produced by ParseTree.
>> [...]
>> Is someone aware of a similar effort?
>> [...]

>
> Hello,
>
> the Ruby 1.9.1p243 that I installed from source came with a library
> called 'ripper' that can produce S-expression parse trees from Ruby
> code, like this:
>
> $ cat foo.rb
> require 'ripper'
> require 'pp'
>
> pp Ripper.sexp %{
> def foo
> :bar
> end
> }
>
> $ ruby foo.rb
> [rogram,
> [[:def,
> [:@ident, "foo", [2, 6]],
> [arams, nil, nil, nil, nil, nil],
> [:body_stmt,
> [[:symbol_literal, [:symbol, [:@ident, "bar", [3, 5]]]]],
> nil,
> nil,
> nil]]]]
>
> I played around with that a little, but didn't try to code anything
> serious. Also, since I'm new to Ruby and haven't used ParseTree
> before, I don't know how compatible the abstract syntax tree
> representations are.
>
> cu,
> Thomas


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ryan Davis
Guest
Posts: n/a
 
      08-04-2009

On Aug 3, 2009, at 23:20 , Macario Ortega wrote:

> Hi, I've been missing ParseTree very badly in 1.9.1. So in my =20
> naivit=E9 I
> decided to try to convert YARV iseq's to Sexp's similar of those
> produced by ParseTree. So far I can convert simple expressions, method
> calls, nested method calls, arrays, hashes, I can extract method
> parameter and default values provided the expression is not too
> complicated.
> At first it seemed easy until I hitted control structures.
>
> Is someone aware of a similar effort?
>
> Does anyone else craves AST manipulation in 1.9.1 as bad as me?
>
> Anyone care to join?


This is pretty awesome. It is gonna only get worse tho.

We talked about doing this a while back and came to the conclusion =20
that it was more work than we were interested in investing. Please =20
prove us wrong and you'll get a least a couple beers at the next =20
rubyconf.

A suggestion: Use test/pt_testcase.rb from the ParseTree project and =20
you'll be a LOT happier. See the test cases from either ruby2c or =20
ruby_parser as examples of test reuse.


 
Reply With Quote
 
Tony Arcieri
Guest
Posts: n/a
 
      08-04-2009
[Note: parts of this message were removed to make it a legal post.]

On Tue, Aug 4, 2009 at 12:20 AM, Macario Ortega <(E-Mail Removed)> wrote:

> Does anyone else craves AST manipulation in 1.9.1 as bad as me?
>


Yes


> Any sugested reads appart from YARV wiki?
>


Does ruby_parser work on 1.9?

http://parsetree.rubyforge.org/

--
Tony Arcieri
Medioh/Nagravision

 
Reply With Quote
 
Macario Ortega
Guest
Posts: n/a
 
      08-05-2009
Tony Arcieri wrote:


>
> Does ruby_parser work on 1.9?
>


Yeah it does but you need to pass it ruby source code not live objects.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Macario Ortega
Guest
Posts: n/a
 
      08-05-2009
Ryan Davis wrote:
> On Aug 3, 2009, at 23:20 , Macario Ortega wrote:



>
> A suggestion: Use test/pt_testcase.rb from the ParseTree project and
> you'll be a LOT happier. See the test cases from either ruby2c or
> ruby_parser as examples of test reuse.



Thanks for the suggestion Ryan! I don't have much time to hack nowadays
but I love ParseTree and there is definitelly a gap in 1.9.1. As I told
I started out of naivite.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      08-05-2009
On Tue, Aug 4, 2009 at 7:56 PM, Macario Ortega<(E-Mail Removed)> wrote:
> Tony Arcieri wrote:
>
>
>>
>> Does ruby_parser work on 1.9?
>>

>
> Yeah it does but you need to pass it ruby source code not live objects.


That's how Ripper works too. Notice in this example:

require 'ripper'
require 'pp'

pp Ripper.sexp %{
def foo
:bar
end
}

The %{ .. } is a string.

- Charlie

 
Reply With Quote
 
Kevin Rutherford
Guest
Posts: n/a
 
      08-05-2009
Hi Macario,

> Does anyone else craves AST manipulation in 1.9.1 as bad as me?


Reek (http://github.com/kevinrutherford/reek/tree) will miss ParseTree
in 1.9 too, because it means that some of its Rspec matchers no longer
work. Without ParseTree (or equivalent) it's not possible to write:

MyClass.should_not reek

> Anyone care to join?


I don't have much time available, but I'll be happy to help.
As Ryan suggests, the starting point will be a decent suite of regression tests.
Cheers,
Kevin
--
m: +44 (0) 797 356 3521
w: http://www.kevinrutherford.co.uk
e: http://www.velocityreviews.com/forums/(E-Mail Removed)
t: @kevinrutherford
l: http://www.linkedin.com/in/kevinrutherford

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what kind of client do i need ?? Hernn Castelo Wireless Networking 3 05-11-2005 06:29 AM
Router problems of a different kind =?Utf-8?B?c2hhZG8yODI=?= Wireless Networking 1 01-31-2005 11:39 PM
Synthesizable (kind of) dual-edge FF Nicolas Matringe VHDL 1 10-12-2004 07:40 PM
Kind of hard, really Charles Firefox 12 08-12-2004 04:05 PM
What kind of problems is Perl best at solving? nb Perl 0 12-29-2003 06:34 PM



Advertisments