Recently I’ve started playing with jrubyparser to check how far I can
go towards implementing AST transformations (similar to what Groovy
has). JRubyParser provides a nice api and it’s fast enough. The only
problem is finding a place to perform AST transformations. I started
with implementing my own load that reads a file, transforms it using
JRubyParser and then evals it. Right now I’m trying to find a better
way to do it. That’s why I’m curious:
Is there a moment when jruby has already read a file but haven’t
evaluated it yet? And is there a callback or similar extension point?
Basically, is there a way to change what was read from the file before
it was evaluated?
Another way to do all these transformations would be to get the
source code of a method and transform it. Is there a way to get the
source code of a method or a class at runtime?
Recently I’ve started playing with jrubyparser to check how far I can
go towards implementing AST transformations (similar to what Groovy
has). JRubyParser provides a nice api and it’s fast enough. The only
problem is finding a place to perform AST transformations. I started
with implementing my own load that reads a file, transforms it using
JRubyParser and then evals it. Right now I’m trying to find a better
way to do it. That’s why I’m curious:
I’d love to see an AST transformation capability in JRubyParser. There
is already some transformation logic in the JRubyParser library under
the refactoring stuff, but I’m not sure whether it’s working right
now. I did play with it a bit recently, and it’s at least partially
functional.
Is there a moment when jruby has already read a file but haven't
evaluated it yet? And is there a callback or similar extension point?
Basically, is there a way to change what was read from the file before
it was evaluated?
There’s no callback for that point in execution, but there easily
could be. Code is passed to the parser, and the parser passes back a
Node for us to interpret or compile. That could easily be hooked to
allow code to manipulate it.
I’d love tos ee something added.
Another way to do all these transformations would be to get the
source code of a method and transform it. Is there a way to get the
source code of a method or a class at runtime?
I’d also love to see a way to get the source code of a given method
I don’t think it would be hard, and it would be very useful.
These would be good projects for someone to work on
Charlie
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.