[system] / trunk / pg / lib / Parser / Function / vector.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/Function/vector.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3370 - (download) (as text) (annotate)
Tue Jul 12 22:29:53 2005 UTC (7 years, 10 months ago) by dpvc
File size: 978 byte(s)
A first pass at making parser error messages localizable.  The
Context()->{error}{msg} hash can be used to specify translations of
the standard messages.  For example,

    Context()->{error}{msg}{'Division by zero'} = "Don't divide by zero, dude!";
    Context()->{error}{msg}{'Function '%s' has too many inputs'} =
        "You passed too many arguments to '%s'";

(I didn't translate into another language, here, but you could do
that, too.)

The msg hash could also be used within answer checkers to make certain
answer messages more appropriate for the given type of expected answer.

    1 #########################################################################
    2 #
    3 #  Implement functions on vectors
    4 #
    5 package Parser::Function::vector;
    6 use strict; use vars qw(@ISA);
    7 @ISA = qw(Parser::Function);
    8 
    9 #
   10 #  Check for a single vector-valued input
   11 #
   12 sub _check {(shift)->checkVector(@_)}
   13 
   14 #
   15 #  Evaluate by promoting to a vector
   16 #    and then calling the routine from Value.pm
   17 #
   18 sub _eval {
   19   my $self = shift; my $name = $self->{name};
   20   my $v = Value::Vector::promote($_[0]);
   21   $v->$name;
   22 }
   23 
   24 #
   25 #  Check for a single vector-valued argument
   26 #  Then promote it to a vector (does error checking)
   27 #    and call the routine from Value.pm
   28 #
   29 sub _call {
   30   my $self = shift; my $name = shift;
   31   Value::Error("Function '%s' has too many inputs",$name) if scalar(@_) > 1;
   32   Value::Error("Function '%s' has too few inputs",$name) if scalar(@_) == 0;
   33   my $v = Value::Vector::promote($_[0]);
   34   $v->$name;
   35 }
   36 
   37 #########################################################################
   38 
   39 1;
   40 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9