views:

234

answers:

2

I understand that the Ruby 1.8 AST is traversed at runtime using a big switch statement, and many things like calling a method in a class or parent module involve the interpreter looking up and down the tree as it goes. Is there a straightforward way of accessing this AST in a Ruby C extension? Does it involve the Ruby extension API, or necessitate hacking the internal data structures directly?

+1  A: 

A good starting point is probably to read the source of the ParseTree library, which lets you get at and mess with the AST from ruby.

Orion Edwards
A: 

Thanks for the tip, you're right - ParseTree seems to be the only code out there with any manipulation of the AST going on, except that it's actually written in RubyInline so its a strange mixture between Ruby and C code. Very interesting reading though.

The other reference of course is eval.c from Ruby itself.

It's going to take a fair bit of reading of both, to get my head around it.

maetl
hey there! out of interest, what are you writing? :)
banister