use strict; use warnings; use Parse::RecDescent; use vars qw( %item @item $return @pair @store ); my $data = do {local $/;<DATA>}; my $parser = Parse::RecDescent->new($data); my @code = ( q/concat(int2string(counter, 1),result)/, q/concat("hello","world")/, q/concat(foo,bar)/, ); $parser->startrule($_) for @code; for (0..$#code) { print "$code[$_]\n"; print "\targ 1 => ", $store[$_][0], "\n"; print "\targ 2 => ", $store[$_][1], "\n"; } __DATA__ startrule: function function: label open_p arg comma arg close_p arg: nested_function | quoted_literal | literal nested_function: label open_p arg comma arg close_p { push @main::pair, join('', @item[1..$#item]); pop @main::store; if (@main::pair == 2) { push @main::store,[@main::pair]; @main::pair = (); } $return = join('', @item[1..$#item]); print STDERR "nested function: $return\n"; } quoted_literal: quote /[^"]+/ quote { push @main::pair, $item[2]; if (@main::pair == 2) { push @main::store,[@main::pair]; @main::pair = (); } print STDERR "quoted literal: $item[2]\n"; $return = $item[2]; } literal: /\w+/i { push @main::pair, $item[1]; if (@main::pair == 2) { push @main::store,[@main::pair]; @main::pair = (); } print STDERR "literal: $item[1]\n"; $return = $item[1]; } label: /[a-zA-Z]\w*/ open_p: /\(/ close_p: /\)/ comma: /,/ quote: /"/
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) Re: Need a regex to match C-style function arg list
by jeffa
in thread Need a regex to match C-style function arg list
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |