Next Higher-Order Parsing 17 

結合Concatenation

        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;
        }
        $atom = conc(lookfor("FUNC"),
                     lookfor("("),
                     $expression,
                     lookfor(")"),
                    );

Next Copyright © 2007 M. J. Dominus