Next | Higher-Order Parsing | 30 |
We've built all this up just by gluing together a very few basic tools:
lookfor() conc() alt()
But the tools themselves were simple
If we needed some new tool, we could build it
For example, "look for A, but only if it doesn't also look like B":
sub this_but_not_that { my ($A, $B) = @_; my $parser = sub { my $in = shift; my ($res, $out) = $A->($in) or return; if ($B->($in)) { return; } return ($res, $out); }; return $parser; }
Next | Copyright © 2007 M. J. Dominus |