Next | Higher-Order Parsing | 17 |
sub conc { my @p = @_; my $parser = sub { my $tokens = shift; my @results; for my $p (@p) { my ($result, $t_new) = $p->($tokens) or return; # failure push @results, $result; $tokens = $t_new; } # all parsers succeeded return (\@results, $tokens); }; return $parser; }
With this definition, atom becomes simply:
$atom = conc(lookfor("FUNC"), lookfor("("), $expression, lookfor(")"), );
Next | Copyright © 2007 M. J. Dominus |