Next | Higher-Order Parsing | 32 |
We've built all this up just by gluing together a very few basic tools:
lookfor() conc() alt()
But the tools themselves are simple
only about 25 lines of code, total
If we need some new tool, we can 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 |