Python and ruby together?

G

Gwen Morse

Is it possible to set up python scripts in such a way that they can
parse ruby files?

ie: I have a script written in ruby.

I have 3rd party program that reads python scripts but not ruby
scripts. I want the 3rd party program to read my ruby script.

Can I load some sort of ruby library via python or do I need to hit
the python books and start studying?

Gwen
 
G

Gregory Brown

Is it possible to set up python scripts in such a way that they can
parse ruby files?

ie: I have a script written in ruby.

I have =A03rd party program that reads python scripts but not ruby
scripts. I want the 3rd party program to read my ruby script.

Does that program allow shell access? Easiest might be to just call
your ruby script from within the python one.
(If it indeed makes sense to do that at all ;)
 
7

7stud --

Gwen said:
Is it possible to set up python scripts in such a way that they can
parse ruby files?


r1test.rb:
---------
puts "hello"
puts "world"


python_prog.py:
-------------
f = open("r1test.rb")

for line in f:
line = line.strip() #chop newline off
pieces = line.split()

print line
print pieces[-1]
print

--output:--
puts "hello"
"hello"

puts "world"
"world"
 
7

7stud --

Hmm...now I wonder if you understand the difference between 'read' or
'parse' and 'execute'.
 
C

Caleb Clausen

Is it possible to set up python scripts in such a way that they can
parse ruby files?

Parsing ruby is very complex, and there are very few complete (or
nearly complete) ruby parsers out there. It's possible that some
python library exists that can parse ruby, but unlikely. Your best bet
is to use one of the existing ruby parsers from a ruby interpreter
running in a separate process, serialize the tree it outputs and
figure out how to unserialize that into python data.

The ruby parsers I know of are:

RedParse (disclaimer: I wrote this one)
ParseTree (+JParseTree for jruby)
ruby_parser
RubyNode
ruby 1.9 + Ripper (which I only discovered today can output a tree)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top