Next | Higher-Order Parsing | 28 |
In Higher-Order Perl, I build a drawing system
The input language to the drawing system contains constructions like:
constraints { ... }
And:
define square extends rectangle { ... }
So I use an even higher-level parser constructor:
sub labeled_block { my ($header, $item, $separator) = @_; $separator = lookfor(";") unless defined $separator; conc($header, lookfor("{"), list_of($item, $separator), lookfor("}")); }
And define really complex parsers with it:
$constraint_block = labeled_block(L("CONSTRAINTS"), $constraint); $definition = labeled_block($Definition_header, $declaration);
Next | Copyright © 2007 M. J. Dominus |