Automating Perl -> Ruby translation?

Has anyone given any thought to this
issue?

Yes, I’m well aware that you can’t get
a “good” translation… I’d settle for
something that did 80% of the grunt
work. Then I could iron out the rest
and hammer it into OO form.

Come on, someone…

Hal

I don’t think you’d get very far. Syntax may not be too difficult,
but libraries…

Gavin

···

On Friday, January 17, 2003, 8:03:52 PM, Hal wrote:

Has anyone given any thought to this
issue?

Yes, I’m well aware that you can’t get
a “good” translation… I’d settle for
something that did 80% of the grunt
work. Then I could iron out the rest
and hammer it into OO form.

Come on, someone…

“Hal E. Fulton” hal9000@hypermetrics.com writes:

Yes, I’m well aware that you can’t get
a “good” translation… I’d settle for
something that did 80% of the grunt
work. Then I could iron out the rest
and hammer it into OO form.

The way to do this is to start with Perl’s B::Deparse library, which
turns the AST of a Perl program back into Perl. If you can modify it
in such a way that it outputs Ruby instead of Perl, then you’re made.

···


“Saving four times is just paranoia. Unless you’re using an Exabyte
5gig/8mm tapedrive.” - Graham Reed, ASR

In article 034a01c2be07$95670380$0300a8c0@austin.rr.com,

···

Hal E. Fulton hal9000@hypermetrics.com wrote:

Has anyone given any thought to this
issue?

Yes, I’m well aware that you can’t get
a “good” translation… I’d settle for
something that did 80% of the grunt
work. Then I could iron out the rest
and hammer it into OO form.

Come on, someone…

Parsing Perl is not easy…
Is there any tool for Perl that gives you a parse tree of some Perl
script? If there is then that’d be a good place to start.

Otherwise, I think that it’s mostly wasted effort… better to spend
energy trying to get something like Cardinal working.

Phil

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

So do it bottom-up :slight_smile: Seriously, it’d help get smoe of the more useful
cpan libraries ported.

martin

···

Gavin Sinclair gsinclair@soyabean.com.au wrote:

I don’t think you’d get very far. Syntax may not be too difficult,
but libraries…

In article 87lm1k57gw.fsf@ddtm.simon-cozens.org,

···

Simon Cozens simon@simon-cozens.org wrote:

“Hal E. Fulton” hal9000@hypermetrics.com writes:

Yes, I’m well aware that you can’t get
a “good” translation… I’d settle for
something that did 80% of the grunt
work. Then I could iron out the rest
and hammer it into OO form.

The way to do this is to start with Perl’s B::Deparse library, which
turns the AST of a Perl program back into Perl. If you can modify it
in such a way that it outputs Ruby instead of Perl, then you’re made.

Ahhh, so such a beast exists… Well that would certainly help.

What would you do about nasty things like, for example, ‘tie’?

Phil

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

There’s a saying among Perl mongers:

“Only Perl can parse Perl” :slight_smile:

Seriously, I’m sure that this is possible, but I’m not sure it’s worth
it. It might be better to translate CPAN to Ruby. Unfortunatelly, nearly
all of CPAN is written with XS, which is a Perl-only tool. I don’t know
how hard it’d be to translate XS to SWIG, but my experience is that XS is
quite complicated.

Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

···

On Sat, 18 Jan 2003, Phil Tomson wrote:

Parsing Perl is not easy…

Hello Phil,

Friday, January 17, 2003, 9:47:16 PM, you wrote:

Parsing Perl is not easy…
Is there any tool for Perl that gives you a parse tree of some Perl
script? If there is then that’d be a good place to start.

Otherwise, I think that it’s mostly wasted effort… better to spend
energy trying to get something like Cardinal working.

of course, perl interpreter. or i am wrong?

···


Best regards,
Bulat mailto:bulatz@integ.ru

I thought we were benefiting from a lot of porting already. What are
some things you want to see?

Gavin

···

On Friday, January 17, 2003, 10:25:42 PM, Martin wrote:

Gavin Sinclair gsinclair@soyabean.com.au wrote:

I don’t think you’d get very far. Syntax may not be too difficult,
but libraries…

So do it bottom-up :slight_smile: Seriously, it’d help get smoe of the more useful
cpan libraries ported.

ptkwt@shell1.aracnet.com (Phil Tomson) writes:

What would you do about nasty things like, for example, ‘tie’?

Nothing special; just instantiate an object of the appropriate class,
and have the translation of the class deal with the dereferencing and
storing methods.

···


The angels want to wear my red shoes.

Hi –

···

On Sat, 18 Jan 2003, Daniel Carrera wrote:

On Sat, 18 Jan 2003, Phil Tomson wrote:

Parsing Perl is not easy…

There’s a saying among Perl mongers:

“Only Perl can parse Perl” :slight_smile:

I thought it was “Only perl can parse Perl” :slight_smile:

David


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Parsing Perl is not easy…

There’s a saying among Perl mongers:

“Only Perl can parse Perl” :slight_smile:

Pedantically, “only perl can parse Perl” (highlighting the distinction
between perl-the-interpreter and Perl-the-language).

Seriously, I’m sure that this is possible, but I’m not sure it’s worth
it. It might be better to translate CPAN to Ruby. Unfortunatelly, nearly
all of CPAN is written with XS, which is a Perl-only tool. I don’t know
how hard it’d be to translate XS to SWIG, but my experience is that XS is
quite complicated.

As Simon Cozens pointed out, we could start by porting some of the
Perl-parsing modules by hand, and bootstrap from there.

martin

···

Daniel Carrera dcarrera@math.umd.edu wrote:

On Sat, 18 Jan 2003, Phil Tomson wrote:

Well, I’d settle for a very crude tool.

I once translated a small Perl program
(200 lines or so) with the help of some
others.

You’d be surprised how much progress I
made just by saying :%s/my $//g in vi.

I’m joking less than you think. Eight or
nine such commands, and the Perl was
starting to look a lot like Ruby.

As for XS: I don’t know what it is.

Anyway, it’s just a thought.

I do have two or three things I want
to translate. If I had a tool, I would
use it, and others might also.

Hal

···

----- Original Message -----
From: “Daniel Carrera” dcarrera@math.umd.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, January 17, 2003 2:13 PM
Subject: Re: Automating Perl → Ruby translation?

Seriously, I’m sure that this is possible, but I’m not sure it’s worth
it. It might be better to translate CPAN to Ruby. Unfortunatelly, nearly
all of CPAN is written with XS, which is a Perl-only tool. I don’t know
how hard it’d be to translate XS to SWIG, but my experience is that XS is
quite complicated.

In article 179409057493.20030121091049@integ.ru,

Hello Phil,

Friday, January 17, 2003, 9:47:16 PM, you wrote:

Parsing Perl is not easy…
Is there any tool for Perl that gives you a parse tree of some Perl
script? If there is then that’d be a good place to start.

Otherwise, I think that it’s mostly wasted effort… better to spend
energy trying to get something like Cardinal working.

of course, perl interpreter. or i am wrong?

Cardinal being a project to create a Ruby frontend for Parrot (the Perl6
VM). If the bird ever flys then it’ll be fairly easy to call Perl
libraries from Ruby.

On the otherhand, there is something to be said for translating your
favorite Perl modules into Ruby. You’ll certainly be able to make them
conform to ‘The Ruby Way’ more easily if you do this by hand than if you
use some automated tool to do it for you and in the end I think you’ll end
up with a better package.

Phil

···

Bulat Ziganshin bulatz@integ.ru wrote:

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

We are, but we could always do with more :slight_smile: Personally, I’d like to see
Ruby ports of a number of the Lingua-EN and Text- modules
(Text::Balanced in particular). And in general, there’s definitely some
reasonably mindless transformation work involved in porting, and there’s
no reason a computer couldn’t handle that part for us.

martin

···

Gavin Sinclair gsinclair@soyabean.com.au wrote:

On Friday, January 17, 2003, 10:25:42 PM, Martin wrote:

So do it bottom-up :slight_smile: Seriously, it’d help get smoe of the more useful
cpan libraries ported.

I thought we were benefiting from a lot of porting already. What are
some things you want to see?

In article 877kd34n4p.fsf@ddtm.simon-cozens.org,

···

Simon Cozens simon@simon-cozens.org wrote:

ptkwt@shell1.aracnet.com (Phil Tomson) writes:

What would you do about nasty things like, for example, ‘tie’?

Nothing special; just instantiate an object of the appropriate class,
and have the translation of the class deal with the dereferencing and
storing methods.

A short example?

Phil

“Or perhaps the truth is less interesting than the facts?”
Amy Weiss (accusing theregister.co.uk of engaging in ‘tabloid journalism’)
Senior VP, Communications
Recording Industry Association of America

Well, I’d settle for a very crude tool.
[snip]
You’d be surprised how much progress I
made just by saying :%s/my $//g in vi.

I wonder how hard it’d be to make a “very crude” tool. That might be
more doable. Let’s see, off the top of my head:

1.- Delete ‘my $’, ‘my @’, ‘my %’.
2.- Delete ‘{’
3.- Replace ‘}’ by ‘end’.
4.- Make a list of methods and reverse the ‘words’ to create a more OO
syntax:

e.g.

sort @array => array.sort

As for XS: I don’t know what it is.

A tool for making Perl extensions in C, akin to SWIG but Perl-specific. I
like SWIG better.

I do have two or three things I want
to translate. If I had a tool, I would
use it, and others might also.

Send me one of them (the simplest one). I’m curious as to how difficult a
crude tool would be.

Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

···

On Sat, 18 Jan 2003, Hal E. Fulton wrote:

In article 043001c2be89$0819c9e0$0300a8c0@austin.rr.com,

From: “Daniel Carrera” dcarrera@math.umd.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, January 17, 2003 2:13 PM
Subject: Re: Automating Perl → Ruby translation?

Seriously, I’m sure that this is possible, but I’m not sure it’s worth
it. It might be better to translate CPAN to Ruby. Unfortunatelly, nearly
all of CPAN is written with XS, which is a Perl-only tool. I don’t know
how hard it’d be to translate XS to SWIG, but my experience is that XS is
quite complicated.

    • Huh? SWIG is a way to hide XS from yourself.

Well, I’d settle for a very crude tool.

I once translated a small Perl program
(200 lines or so) with the help of some
others.

You’d be surprised how much progress I
made just by saying :%s/my $//g in vi.

I’m joking less than you think. Eight or
nine such commands, and the Perl was
starting to look a lot like Ruby.

As for XS: I don’t know what it is.

    • Consider yourself very lucky. IMHO, it’s
      the big reason to prefer Ruby over Perl.
      The Ruby C API is a joy compared to XS.

Anyway, it’s just a thought.

I do have two or three things I want
to translate. If I had a tool, I would
use it, and others might also.

    • Your only chance is to trick Simon into
      using his magic B modules to accomplish
      this for you.
    • Booker C. Bense
···

Hal E. Fulton hal9000@hypermetrics.com wrote:

----- Original Message -----

Daniel Carrera dcarrera@math.umd.edu writes:

I wonder how hard it’d be to make a “very crude” tool. That might be
more doable. Let’s see, off the top of my head:

2.- Delete ‘{’
3.- Replace ‘}’ by ‘end’.

Ack, you’ve just broken hashes-- fix those first!

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.

Oh, come on, XS isn’t that bad. Really, it isn’t. (Granted, I design
and implement interpreters for fun, so my opinion may be somewhat
skewed, but…)

···

At 9:25 AM +0900 1/24/03, bbense+comp.lang.ruby.Jan.23.03@telemark.slac.stanford.edu wrote:

In article 043001c2be89$0819c9e0$0300a8c0@austin.rr.com,
Hal E. Fulton hal9000@hypermetrics.com wrote:

----- Original Message -----
From: “Daniel Carrera” dcarrera@math.umd.edu
As for XS: I don’t know what it is.

    • Consider yourself very lucky. IMHO, it’s
      the big reason to prefer Ruby over Perl.
      The Ruby C API is a joy compared to XS.


Dan

--------------------------------------“it’s like this”-------------------
Dan Sugalski even samurai
dan@sidhe.org have teddy bears and even
teddy bears get drunk