in reply to Appropriate CPAN namespace for perl parser

Wiser souls than I will counsel you that only perl can parse Perl. Once upon a time I embarked on a somewhat similar project. Here is some code that you may like to use in testing. Much of it came from insults and taunts from the on again off again monk Abigail

print <<'drom"edary',<<"f#f",<<'=pod',<< ''; #comment Just another Perl Hacker drom"edary #foo f#f #bar =pod #foo #too #you $_ = "Just another Python# Hacker\n"; s {Python#} [Perl]; print; $_=<<'=pod'; Just another Perl Hacker =pod print; s[foo#] #comment [bar#]; #comment m{ \#[#] # comment \w+: # comment [#] # comment \# # comment \} # comment }x; # $_ = "Just another Perl Hacker\n"; { print if m\foo\#comment } $_ = "Just another Perl Hacker # No comment, no comment! # Yes, really! # I am really a Perl Hacker! ";print; (1) ? print "foo#\n" : print "bar#\n"; # foobar print "\"Goodnight I'm tired!\" # No comment here\n"; # but one here sleep 1; # Because tired print "Goodbye!\n"; BEGIN {if ($ARGV [0]) {eval 'sub foo () {print}'} else {eval 'sub foo ($) {print}'} } $_ = "Just another Perl Hacker\n"; foo /#/; 1;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Appropriate CPAN namespace for perl parser
by adamk (Chaplain) on Feb 12, 2002 at 23:22 UTC
    I haven't listed it anywhere yet, but I anyone would like to have a play with a CGI frontend to the modules, you can at

    http://doug.idleplay.net/cgi-bin/CPAN/applications/psp/psp.pl

    As for the code above, it is mostly ok. The quote engine is written directly off the PODs on quote and quote-likes, and is quite accurate. The only one that gets it ( which is a fixable bug ) is

    print if m\foo\#comment
    The rest I feel should be ok. Try it for yourself. One quick note on that. There is data attached to the quotes as to where in the quote the actual data is, so comments are recognised as comments, but they will not appear that way in the syntax highlighting ( yet ). I have some requirements that Perl itself doesn't have, I can't just discard comments or Pod, so naturally the parsing process is a bit different.