[system] / trunk / pg / macros / contextLimitedNumeric.pl Repository:
ViewVC logotype

Annotation of /trunk/pg/macros/contextLimitedNumeric.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3371 - (view) (download) (as text)

1 : dpvc 2726 loadMacros("Parser.pl");
2 :    
3 :     sub _contextLimitedNumeric_init {}; # don't load it again
4 :    
5 :     ##########################################################
6 :     #
7 :     # Implements a context in which numbers can be entered,
8 :     # but no operations are permitted between them.
9 :     #
10 :     # There are two versions: one for lists of numbers
11 :     # and one for a single number. Select them using
12 :     # one of the following commands:
13 :     #
14 :     # Context("LimitedNumeric-list");
15 :     # Context("LimiteNumeric");
16 :     #
17 :    
18 :     package LimitedNumeric::UOP::minus;
19 :     our @ISA = qw(Parser::UOP::minus);
20 :    
21 :     sub _check {
22 :     my $self = shift;
23 :     $self->SUPER::_check;
24 :     my $uop = $self->{def}{string} || $self->{uop};
25 : dpvc 3371 $self->Error("Can't use '%s' in this context",$uop)
26 : dpvc 2726 unless $self->{op}->class eq 'Number';
27 :     }
28 :    
29 :     package main;
30 :    
31 :     $context{LimitedNumeric} = Context("Numeric");
32 :     $context{LimitedNumeric}->operators->set('u-' => {class => 'LimitedNumeric::UOP::minus'});
33 :     $context{LimitedNumeric}->operators->undefine(
34 :     '+', '-', '*', '* ', ' *', ' ', '/', '/ ', ' /', '^', '**',
35 :     'U', '.', '><', 'u+', '!', '_',
36 :     );
37 :     $context{LimitedNumeric}->parens->undefine('|','{','(','[');
38 :     Parser::Context::Functions::Disable('All');
39 :    
40 :     $context{'LimitedNumeric-List'} = $context{LimitedNumeric}->copy;
41 :    
42 :     $context{LimitedNumeric}->operators->undefine(',');
43 :    
44 :     Context("LimitedNumeric");

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9