gmpassos has asked for the wisdom of the Perl Monks concerning the following question:

I want to know if there is a way (module) to parse a Perl code (source) and have a tree of it, to than rewrite this code with the style that the user want. Note that this need to be done without run/load the code by the interpreter.

This is for an Perl editor that I'm working on, and I want to know if exist some good module to do that, or I need to write it?! If I need to write it where I can find a good doc about all the definition of all the operators, types, etc... Since I need to make something compatible with the Perl internal definition, not invent it.

Graciliano M. P.
"The creativity is the expression of the liberty".

Replies are listed 'Best First'.
•Re: Parsong a Perl code!
by merlyn (Sage) on Apr 21, 2003 at 19:04 UTC
Re: Parsong a Perl code!
by The Mad Hatter (Priest) on Apr 21, 2003 at 19:04 UTC
Re: Parsong a Perl code!
by Solo (Deacon) on Apr 21, 2003 at 19:27 UTC
    Perl::Tidy doesn't build a tree out of the source, but it does have a lot of features for controlling the format of the output (how much this helps you depends on what you mean by 'style').

    --Solo

    --
    Well, I suppose I could hotwire this thing.
      I have tested PerlTidy and is very cool! Works for me!

      Thanks for the tip. ;-P

      But I still think that Perl5 need a parser for it. The project http://ali.as/PSP/ is there and need some help.

      Note, the Perl editor is in Perl, very easy to link any Perl module or code! ;-P

      Graciliano M. P.
      "The creativity is the expression of the liberty".

Re: Parsong a Perl code!
by fokat (Deacon) on Apr 21, 2003 at 19:27 UTC

    I've read many times in the monastery that Only Perl can parse Perl properly. The reason for this has to do IMHO with the dynamic nature of the language.

    You could probably use the B modules in order to help with the parsing and perhaps, beutification, although this would probably force you to embed a Perl interpreter in your editor. A few days ago there was a discussion about a shameless plug review of a product that pseudo-obfuscated Perl code where a very effective technique using the B::* modules was demonstrated. If it is good for (de)obfuscating, it is also good for changing code styles.

    Best regards

    -lem, but some call me fokat