Dear Monks,

Here's some parser code I've written in RecDescent.

The data format has dynamic columns e.g., the cpu column specifies there are 4 cpus and that the next 4 columns contain cpu values. Using another prayer here Parse::RecDescent and Dynamically Matched Subrule Repetition I've got some code, via recusion, that does what I want.

However,if I add an autoaction or an autotree directive (uncomment these in the code to replicate). The code breaks - the recursion fails. There is something i'm not understanding regarding the way code blocks return (I think). It says in the manual that autoactions (and autotree) will not modify rules that have code blocks so I don't get why the recursion stops. Any thoughts wise ones?

(an aside: is { [ $item[1] ] } equivalent to { $return=[ $item[1] ]} )?

#!/usr/bin/perl use strict; use warnings; use Parse::RecDescent; use Data::Dumper; #$::RD_AUTOACTION = q { print $item[0]."=".$item[1]."\n" }; my $parser=Parse::RecDescent->new(<<'__END_OF_GRAMMAR__'); #<autotree> line: time load cpus avg_time avg_load eof {\%item} time: int load: int avg_time: int avg_load: int #Recursively build a list of cpus based on the number of cpus reported cpus: cpu_num cpu_list[ $item{cpu_num} ] { $return=[ $item[0], $item[2 +] ] } cpu_list: { $arg[0] == 0 ? $return=[] : undef } | cpu_elem cpu_list[ $arg[0]-1 ] { $return=[ $item[1], @{$item +[2]} ] } cpu_elem: int cpu_num: int int: /\d+/ eof: /\Z/ __END_OF_GRAMMAR__ my @input=( "10 12 4 3 2 9 2 7 567", "8 9 3 1 2 3 8 8", "6 2 1 1 4 8", "6 2 0 1 4", ); foreach my $input(@input){ print Dumper($parser->line($input)); };

In reply to Parse::RecDescent and auto{actions,trees} and stuff by mattford63

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.