From: dpvc v. a. <we...@ma...> - 2005-08-13 20:54:08
|
Log Message: ----------- Make formulas that produce lists get default open and close parens, and have them retained in Formula() results. Modified Files: -------------- pg/lib: Parser.pm pg/lib/Value: Formula.pm Revision Data ------------- Index: Parser.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser.pm,v retrieving revision 1.28 retrieving revision 1.29 diff -Llib/Parser.pm -Llib/Parser.pm -u -r1.28 -r1.29 --- lib/Parser.pm +++ lib/Parser.pm @@ -26,8 +26,9 @@ my $context = Parser::Context->current; my $class = $context->{parser}{Formula}; my $string = shift; - $string = Value::List->new($string,@_) - if scalar(@_) > 0 || ref($string) eq 'ARRAY'; + $string = Value::List->new($string,@_) if scalar(@_) > 0; + $string = Value::List->new($string)->with(open=>'[',close=>']') + if ref($string) eq 'ARRAY'; my $math = bless { string => undef, tokens => [], tree => undef, Index: Formula.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Formula.pm,v retrieving revision 1.33 retrieving revision 1.34 diff -Llib/Value/Formula.pm -Llib/Value/Formula.pm -u -r1.33 -r1.34 --- lib/Value/Formula.pm +++ lib/Value/Formula.pm @@ -34,9 +34,14 @@ '""' => sub {shift->stringify(@_)}; # -# Call Parser to make the new item +# Call Parser to make the new item, copying important +# fields from the tree. # -sub new {shift; $pkg->SUPER::new(@_)} +sub new { + shift; my $self = $pkg->SUPER::new(@_); + foreach my $id ('open','close') {$self->{$id} = $self->{tree}{$id}} + return $self; +} # # Create the new parser with no string @@ -66,6 +71,8 @@ sub isZero {(shift)->{tree}{isZero}} sub isOne {(shift)->{tree}{isOne}} +sub isSetOfReals {(shift)->type =~ m/Interval|Set|Union/} + ############################################ # # Create a BOP from two operands @@ -97,7 +104,7 @@ $l = $parser->{Value}->new($formula,$l) unless ref($l) =~ m/^Parser::/; $r = $parser->{Value}->new($formula,$r) unless ref($r) =~ m/^Parser::/; $bop = 'U' if $bop eq '+' && - ($l->type =~ m/Interval|Union|Set/ || $r->type =~ m/Interval|Union|Set/); + ($l->type =~ m/Interval|Set|Union/ || $r->type =~ m/Interval|Set|Union/); $formula->{tree} = $parser->{BOP}->new($formula,$bop,$l,$r); $formula->{variables} = $formula->{tree}->getVariables; return $formula->eval if scalar(%{$formula->{variables}}) == 0; |