Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: Re: Parsing Perl in Perl

by gnat (Beadle)
on Jun 14, 2000 at 23:44 UTC ( [id://18164]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing Perl in Perl
in thread Parsing Perl in Perl

He said he wants a Perl code pretty-printer. There was one submitted as a paper to the Perl Conference a year or two ago, but it never was released as a final product.

Update: Apache::PrettyPerl is a mod_perl module to turn Perl code into syntax-highlighted HTML on the fly. It might be worth a look, too.

I've seen hacks that use the C formatter indent, but nothing's done a great job with it. The problem is that Perl is so bloody flexible, it's possible to write code that doesn't look like code to most pretty-printers.

The a2ps program claims to handle Perl, but I don't know how well.

There are two in-Perl solutions. The first is the B::DeParse module, which takes the compiled form of your program and spits it back out as Perl code. This takes some guesswork, though, as your program is seen after Perl has optimized it. The module is still under development, so feel free to fix any bugs you find :-)

The second solution is to write your own. Good luck! A good place to start might be the Text::Balanced module. It's not as heavyweight as Parse::RecDescent. Perl is a complicated beast, but you might be able to do rudimentary parsing using either module.

Let us know how the search goes. I'm sure many others would like a Perl pretty-printer.

Replies are listed 'Best First'.
RE: RE: Re: Parsing Perl in Perl
by awwaiid (Friar) on Jun 15, 2000 at 07:11 UTC

    *Sigh*. Okay. After a bit of research looks like I'm going for your second solution. Apache::PrettyPerl is pretty nice and could be converted for a general perl syntax highlighter... but as you said thats not what I want.

    So... I'm going to write a module that parses perl into a tree of some kind, and then I can do all kinds of stuff with that. Including of course a pretty-printer. If any of you have any comments on that plan... I'd be glad to hear them!

    --Brock (awwaiid@auk.cx)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://18164]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-29 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found