[system] / trunk / pg / lib / Value / String.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Value/String.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2660 - (download) (as text) (annotate)
Fri Aug 20 15:52:32 2004 UTC (15 years, 6 months ago) by dpvc
File size: 1544 byte(s)
A number of adjustments to get negative infinities to work better.
They used to be stored as separate Parser strings, but now they are
flagged versions of a single string.

All of the problems are really due to the fact that there is no
Infinity class in the Parser (only a Value version).  That should be
changed, but will require some work, and can be put off for now.

It would be best if the classes within the two packages would match up
nearly 1-to-1, but for historical reasons, they don't.  Since the
introduction of Real, String and Infinity classes to the Value
package, The Infinity class is the one main difference between the
two, and once that is fixed, everything needs to be looked over to
check for unnecessary complications due to the historical lack of classes
in one or the other package.

    1 ###########################################################################
    2 
    3 package Value::String;
    4 my $pkg = 'Value::String';
    5 
    6 use strict;
    7 use vars qw(@ISA);
    8 @ISA = qw(Value);
    9 
   10 use overload
   11        '.'   => \&Value::_dot,
   12        '<=>' => \&compare,
   13        'cmp' => \&compare,
   14   'nomethod' => \&Value::nomethod,
   15         '""' => \&Value::stringify;
   16 
   17 #
   18 #  Create a string object
   19 #
   20 sub new {
   21   my $self = shift; my $class = ref($self) || $self;
   22   my $x = join('',@_);
   23   if ($Parser::installed) {
   24     Value::Error("Unrecognized string '$x'")
   25       unless $$Value::context->{strings}{$x};
   26   }
   27   bless {data => [$x]}, $class;
   28 }
   29 
   30 #
   31 #  Return the appropriate data.
   32 #
   33 sub length {1}
   34 sub typeRef {$Value::Type{string}}
   35 sub value {shift->{data}[0]}
   36 
   37 ##################################################
   38 
   39 #
   40 #  Convert to a string object
   41 #
   42 sub promote {
   43   my $x = shift; $x = [$x,@_] if scalar(@_) > 0;
   44   $x = Value::makeValue($x); $x = join('',@{$x}) if ref($x) eq 'ARRAY';
   45   $x = $pkg->make($x) unless Value::isValue($x);
   46   return $x;
   47 }
   48 
   49 ############################################
   50 #
   51 #  Operations on strings
   52 #
   53 
   54 sub compare {
   55   my ($l,$r,$flag) = @_;
   56   if ($l->promotePrecedence($r)) {return $r->compare($l,!$flag)}
   57   $r = promote($r); if ($flag) {my $tmp = $l; $l = $r; $r = $tmp}
   58   return $l->value cmp $r->value;
   59 }
   60 
   61 ############################################
   62 #
   63 #  Generate the various output formats
   64 #
   65 
   66 sub TeX {'{\rm '.shift->value.'}'}
   67 sub perl {"'".shift->value."'"}
   68 
   69 ###########################################################################
   70 
   71 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9