File out as Ruby - Possible ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

File out as Ruby - Possible ?

cedreek
Hi,

Do you know if it's possible to export smalltalk code in ruby ?
I have to port a small app I did and so, it could help me :)

I don't think there's an existing tool, but maybe some directions...
Actually, I'd prefer writing a simple tool to do that rather than
doing all by hand.

I don't expect it to work out of the box, but just save me some time.

TIA

--
Cédrick

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

Lukas Renggli
Have a look at the RB AST. You can traverse the AST similar to the
pretty-printer that is included (RBFormatter and
RBConfigurableFormatter) and instead emit Ruby. I've done something
similar for Javascript, and others have done it for other languages.

Lukas

On 10 February 2010 16:51, Cédrick Béler <[hidden email]> wrote:

> Hi,
>
> Do you know if it's possible to export smalltalk code in ruby ?
> I have to port a small app I did and so, it could help me :)
>
> I don't think there's an existing tool, but maybe some directions...
> Actually, I'd prefer writing a simple tool to do that rather than
> doing all by hand.
>
> I don't expect it to work out of the box, but just save me some time.
>
> TIA
>
> --
> Cédrick
>
>



--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

cedreek
Cool... thanks for the info.
I guess this is time I go deeper in AST and friends...

I'll see how it goes and I probably come back :)

2010/2/10 Lukas Renggli <[hidden email]>:

> Have a look at the RB AST. You can traverse the AST similar to the
> pretty-printer that is included (RBFormatter and
> RBConfigurableFormatter) and instead emit Ruby. I've done something
> similar for Javascript, and others have done it for other languages.
>
> Lukas
>
> On 10 February 2010 16:51, Cédrick Béler <[hidden email]> wrote:
>> Hi,
>>
>> Do you know if it's possible to export smalltalk code in ruby ?
>> I have to port a small app I did and so, it could help me :)
>>
>> I don't think there's an existing tool, but maybe some directions...
>> Actually, I'd prefer writing a simple tool to do that rather than
>> doing all by hand.
>>
>> I don't expect it to work out of the box, but just save me some time.
>>
>> TIA
>>
>> --
>> Cédrick
>>
>>
>
>
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Cédrick

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

cedreek
Ok here are some questions to see if I'm on the right track.

From what I've guessed I need to create my own formatter
(RubyFormatter) by basically rewriting all private-formating methods
(am I right here ?).

Then, I use the parser and the RubyFormatter. But what I want is
export a package, ie. classes with their methods and extension
methods. I can't parse directly a full class nor a package... can I
directly ? I guess not

So I need to parse each class definition (and class class definition),
format them,  then parse/format each method source (probably better to
get the code expressions from the MCWorkingCopy or PackageInfo I
guess)...

RBParser parseExpression: MyClass definition.

Then something like:
methodsRefs do: [:mr | RBParser parseMethod: mr sourceCode]

...
I'll try later but if you have any comments... :)

TIA

Cédrick

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

Lukas Renggli
> From what I've guessed I need to create my own formatter
> (RubyFormatter) by basically rewriting all private-formating methods
> (am I right here ?).

You can't probably reuse anything. I would just subclass
RBProgramNodeVisitor and implement all the #accept* methods.
RBFormatter is just an example of how that can be done.

> Then, I use the parser and the RubyFormatter. But what I want is
> export a package, ie. classes with their methods and extension
> methods. I can't parse directly a full class nor a package... can I
> directly ? I guess not

Yeah, that only converts a single method.

> So I need to parse each class definition (and class class definition),
> format them,  then parse/format each method source (probably better to
> get the code expressions from the MCWorkingCopy or PackageInfo I
> guess)...
>
> RBParser parseExpression: MyClass definition.

That's not what you want. Ruby classes look very different to
Smalltalk class definitions. I would do something like:

env := BrowserEnvironment new forPackageNames: #('MyPackage').
env classesDo: [ :class |
    stream := FileStream on: class name , '.rb'.
    " write header of class definition for 'class' "
    env selectorsForClass: class do: [ :selector |
       tree := class parseTreeFor: selector.
       RubyFormatter format: tree on: stream ].
    " write footer of class definition for 'class' "
    stream close ]

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

cedreek
Lots of useful pointer...

Thanks a lot Lukas...


>
> That's not what you want. Ruby classes look very different to
> Smalltalk class definitions. I would do something like:
>
> env := BrowserEnvironment new forPackageNames: #('MyPackage').
> env classesDo: [ :class |
>    stream := FileStream on: class name , '.rb'.
>    " write header of class definition for 'class' "
>    env selectorsForClass: class do: [ :selector |
>       tree := class parseTreeFor: selector.
>       RubyFormatter format: tree on: stream ].
>    " write footer of class definition for 'class' "
>    stream close ]
>
> Lukas
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Cédrick

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

Stefan Marr-4
In reply to this post by Lukas Renggli

On 10 Feb 2010, at 17:34, Lukas Renggli wrote:

> Have a look at the RB AST. You can traverse the AST similar to the
> pretty-printer that is included (RBFormatter and
> RBConfigurableFormatter) and instead emit Ruby. I've done something
> similar for Javascript, and others have done it for other languages.
Since it is already on-topic: Is there something which exports my nice Smalltalk code to some approximate, maybe even with holes, representation in Java code?

Thanks
Stefan


>
> Lukas
>
> On 10 February 2010 16:51, Cédrick Béler <[hidden email]> wrote:
>> Hi,
>>
>> Do you know if it's possible to export smalltalk code in ruby ?
>> I have to port a small app I did and so, it could help me :)
>>
>> I don't think there's an existing tool, but maybe some directions...
>> Actually, I'd prefer writing a simple tool to do that rather than
>> doing all by hand.
>>
>> I don't expect it to work out of the box, but just save me some time.
>>
>> TIA
>>
>> --
>> Cédrick
>>
>>
>
>
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 3956
Fax:   +32 2 629 3525


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

Mariano Martinez Peck


On Wed, Feb 10, 2010 at 7:53 PM, Stefan Marr <[hidden email]> wrote:

On 10 Feb 2010, at 17:34, Lukas Renggli wrote:

> Have a look at the RB AST. You can traverse the AST similar to the
> pretty-printer that is included (RBFormatter and
> RBConfigurableFormatter) and instead emit Ruby. I've done something
> similar for Javascript, and others have done it for other languages.
Since it is already on-topic: Is there something which exports my nice Smalltalk code to some approximate, maybe even with holes, representation in Java code?

Thanks
Stefan


>
> Lukas
>
> On 10 February 2010 16:51, Cédrick Béler <[hidden email]> wrote:
>> Hi,
>>
>> Do you know if it's possible to export smalltalk code in ruby ?
>> I have to port a small app I did and so, it could help me :)
>>
>> I don't think there's an existing tool, but maybe some directions...
>> Actually, I'd prefer writing a simple tool to do that rather than
>> doing all by hand.
>>
>> I don't expect it to work out of the box, but just save me some time.
>>
>> TIA
>>
>> --
>> Cédrick
>>
>>
>
>
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 3956
Fax:   +32 2 629 3525


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] File out as Ruby - Possible ?

SergeStinckwich
In reply to this post by Lukas Renggli
Yes, Lukas show me how to do that. It's very easy.

On Wed, Feb 10, 2010 at 11:34 PM, Lukas Renggli <[hidden email]> wrote:

> Have a look at the RB AST. You can traverse the AST similar to the
> pretty-printer that is included (RBFormatter and
> RBConfigurableFormatter) and instead emit Ruby. I've done something
> similar for Javascript, and others have done it for other languages.
>
> Lukas
>
> On 10 February 2010 16:51, Cédrick Béler <[hidden email]> wrote:
>> Hi,
>>
>> Do you know if it's possible to export smalltalk code in ruby ?
>> I have to port a small app I did and so, it could help me :)
>>
>> I don't think there's an existing tool, but maybe some directions...
>> Actually, I'd prefer writing a simple tool to do that rather than
>> doing all by hand.
>>
>> I don't expect it to work out of the box, but just save me some time.
>>
>> TIA
>>
>> --
>> Cédrick
>>
>>
>
>
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Serge Stinckwich
UMI UMMISCO 209 (IRD/UPMC), Hanoi, Vietnam
Smalltalkers do: [:it | All with: Class, (And love: it)]
http://doesnotunderstand.org/

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project