[system] / trunk / pg / lib / Parser / Context / Operators.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/Context/Operators.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3483 - (download) (as text) (annotate)
Fri Aug 12 01:21:48 2005 UTC (14 years, 4 months ago) by dpvc
File size: 1407 byte(s)
Added redefine() function to complement undefine() for various
Context() values.  For example

      Context()->operators->undefine('+');

makes '+' undefined, but

      Context()->operators->redefine('+');

will put it back.  You can specify a context from which to take the
redefinition, and a name in that context, as in

      Context()->operators->redefine('U',from=>"Interval");
      Context()->operators->redefine('u',from=>"Interval",using=>"U");
      Context()->operators->redefine('U',from=>$content);

where $content is a reference to a Context object.

The undefine() function lets you undefine several items at once, as in

      Context()->operators->undefine('+','-');

For redefine, you must put multiple names in square brackets because
of the optional parmeters:

      Context()->operators->redefine(['+','-']);

    1 #########################################################################
    2 #
    3 #  Implements the list of Operators
    4 #
    5 package Parser::Context::Operators;
    6 use strict;
    7 use vars qw (@ISA);
    8 @ISA = qw(Value::Context::Data);
    9 
   10 sub init {
   11   my $self = shift;
   12   $self->{dataName} = 'operators';
   13   $self->{name} = 'operator';
   14   $self->{Name} = 'operator';
   15   $self->{namePattern} = '.+';
   16 }
   17 
   18 #
   19 #  Remove an operator from the list by assigning it
   20 #    the undefined operator.  This means it will still
   21 #    be recognized by the parser, but will generate an
   22 #    error message whenever it is used.
   23 #
   24 sub undefine {
   25   my $self = shift;
   26   my @data = ();
   27   foreach my $x (@_) {
   28     if ($self->{context}{operators}{$x}{type} eq 'unary') {
   29       push(@data,$x => {
   30   class => 'Parser::UOP::undefined',
   31   oldClass => $self->get($x)->{class},
   32       });
   33     } else {
   34       push(@data,$x => {
   35   class => 'Parser::BOP::undefined',
   36   oldClass => $self->get($x)->{class},
   37       });
   38     }
   39   }
   40   $self->set(@data);
   41 }
   42 
   43 sub redefine {
   44   my $self = shift; my $X = shift;
   45   return $self->SUPER::redefine($X,@_) if scalar(@_) > 0;
   46   $X = [$X] unless ref($X) eq 'ARRAY';
   47   my @data = ();
   48   foreach my $x (@{$X}) {
   49     my $oldClass = $self->get($x)->{oldClass};
   50     push(@data,$x => {class => $oldClass, oldClass => undef})
   51       if $oldClass;
   52   }
   53   $self->set(@data);
   54 }
   55 
   56 #########################################################################
   57 
   58 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9