From: Eric Hodel Date: 2004-11-11T03:43:27+09:00 Subject: Re: Ruby code generation: string vs. AST based (2.0 or beyond) On Nov 9, 2004, at 10:43 PM, itsme213 wrote: > Code generation in ruby is great. > > The only thing I find is that, since it is essentially all string > manipulation prior to eval, none of it is executable (or testable!) > until it > is eval'd. So I find myself writing straight code, testing it, then > mentally > abstracting out the string patterns in that code, then using those in > my > code generation. > > Reading those string patterns more than a day later makes my brain > hurt. > > What are the chances, somewhere in or beyond 2.0, of code generation > being > based on something more like the following: > - write and test executable code > - get access to an AST of that code itself > - implement code generation by cloning/modifying the AST clone Not released just yet, but using ParseTree (a soon to be released RubyForge project), Ryan Davis and myself are working on a something similar. We have loads of cool tools to help us munge the AST to do horrible things. (If you've been hanging out on #ruby-lang, you probably know what that project is.) > This would require a published AST, some manipulations on it, and an > eval > that takes ASTs. Well, you could probably emit Ruby code instead from the modified AST instead, then run the munged Ruby code through the interpreter in a second stage...