Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

acme (189)

acme
  (email not shown publicly)
http://www.astray.com/

Leon Brocard (aka acme) is an orange-loving Perl eurohacker with many varied contributions to the Perl community, including the GraphViz module on the CPAN. YAPC::Europe was all his fault. He is still looking for a Perl Monger group he can start which begins with the letter 'D'.

Journal of acme (189)

Monday July 09, 2007
04:44 AM

MAD

[ #33754 ]

Now that Perl 5.9.5 is out, you can finally play with Misc Attribution Declaration to use the perl parser for fun and profit. First you compile it with something like:

./configure.gnu --prefix=/home/acme/perl595 -Dusedevel -Dmad=y
make && make test && make install

Then if you have a foo.pl:

my $a = 1;
my $b = 2;
print $a + $b;

Then running "PERL_XMLDUMP="foo.xml" ./perl foo.pl " gives the following in foo.xml:

<op_leave seq="0 -> DONE" targ="1" flags="VOID,KIDS,PARENS"
        private="REFCOUNTED"
        refcnt="1">
    <op_enter seq="1 -> 2" />
    <op_null seq="0 -> (2)" flags="VOID">
        <madprops>
            <mad_sv key=";" val=""/>
        </madprops>
    </op_null>
    <op_nextstate seq="2 -> 3" flags="VOID"
            line="1"
            package="main">
        <madprops>
            <mad_sv key=";" val=";"/>
            <mad_sv key="#;" val="&#xA;"/>
        </madprops>
    </op_nextstate>
    <op_sassign seq="5 -> 6" flags="VOID,KIDS,STACKED">
        <madprops>
            <mad_sv key="o" val="="/>
            <mad_sv key="_o" val=" "/>
        </madprops>
        <op_const seq="3 -> 4" flags="SCALAR"
                 IV="1">
            <madprops>
                <mad_sv key="X" val="1"/>
                <mad_sv key="_X" val=" "/>
            </madprops>
        </op_const>
        <op_padsv seq="4 -> 5" targ="1" flags="SCALAR,REF,MOD,SPECIAL"
                private="INTRO">
            <madprops>
                <mad_sv key="$" val="$a"/>
                <mad_sv key="_$" val=" "/>
                <mad_sv key="d" val="my"/>
                <mad_sv key="_d" val=""/>
            </madprops>
        </op_padsv>
    </op_sassign>
    <op_nextstate seq="6 -> 7" flags="VOID"
            line="2"
            package="main">
        <madprops>
            <mad_sv key=";" val=";"/>
            <mad_sv key="#;" val="&#xA;"/>
        </madprops>
    </op_nextstate>
    <op_sassign seq="9 -> 10" flags="VOID,KIDS,STACKED">
        <madprops>
            <mad_sv key="o" val="="/>
            <mad_sv key="_o" val=" "/>
        </madprops>
        <op_const seq="7 -> 8" flags="SCALAR"
                 IV="2">
            <madprops>
                <mad_sv key="X" val="2"/>
                <mad_sv key="_X" val=" "/>
            </madprops>
        </op_const>
        <op_padsv seq="8 -> 9" targ="2" flags="SCALAR,REF,MOD,SPECIAL"
                private="INTRO">
            <madprops>
                <mad_sv key="$" val="$b"/>
                <mad_sv key="_$" val=" "/>
                <mad_sv key="d" val="my"/>
            </madprops>
        </op_padsv>
    </op_sassign>
    <op_nextstate seq="10 -> 11" flags="VOID"
            line="3"
            package="main">
        <madprops>
            <mad_sv key=";" val=";"/>
            <mad_sv key="_;" val=""/>
            <mad_sv key="#;" val="&#xA;"/>
        </madprops>
    </op_nextstate>
    <op_print seq="15 -> 16" flags="SCALAR,KIDS">
        <madprops>
            <mad_sv key="o" val="print"/>
        </madprops>
        <op_pushmark seq="11 -> 12" flags="SCALAR" />
        <op_add seq="14 -> 15" targ="3" flags="SCALAR,KIDS">
            <madprops>
                <mad_sv key="o" val="+"/>
                <mad_sv key="_o" val=" "/>
            </madprops>
            <op_padsv seq="12 -> 13" targ="1" flags="SCALAR">
                <madprops>
                    <mad_sv key="$" val="$a"/>
                    <mad_sv key="_$" val=" "/>
                </madprops>
            </op_padsv>
            <op_padsv seq="13 -> 14" targ="2" flags="SCALAR">
                <madprops>
                    <mad_sv key="$" val="$b"/>
                    <mad_sv key="_$" val=" "/>
                </madprops>
            </op_padsv>
        </op_add>
    </op_print>
    <op_null seq="0 -> (16)" flags="VOID" />
</op_leave>

Figure out what all that XML means and you can write the first correct Perl syntax highlighter, implement JPerl (Jerl?), save the planet...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.