# # This software is Copyright 2005 by Elsevier Inc. You may use it # under the terms of the license at http://perl.plover.com/hop/LICENSE.txt . # ### ### operator ### ## Chapter 9 section 4.4 sub operator { my ($subpart, @ops) = @_; my (@alternatives); for my $operator (@ops) { my ($op, $opfunc) = @$operator; push @alternatives, T(concatenate($op, $subpart), sub { my $subpart_value = $_[1]; sub { $opfunc->($_[0], $subpart_value) } }); } my $result = T(concatenate($subpart, star(alternate(@alternatives))), sub { my ($total, $funcs) = @_; for my $f (@$funcs) { $total = $f->($total); } $total; }); }