From: dpvc v. a. <we...@ma...> - 2005-08-30 12:20:38
|
Log Message: ----------- The perl method for UOP and BOP now put spaces around the operator, to prevent Perl from thinking that things like -e is a file test and *Parser::Function->call is a name reference. (Some of these had been done by hand earlier, but now the base BOP and UOP classes handle it, so we should not have problems in the future). I removed the ad hoc fixes from several other locations (Parser/Function.pm, Parser/Context/Default.pm). Also extended the operator definitions to allow operators to create function-call syntax in perl mode (for when the operator doesn't correspond to a perl operator). Modified Files: -------------- pg/lib/Parser: BOP.pm Function.pm UOP.pm pg/lib/Parser/Context: Default.pm pg/lib/Parser/UOP: factorial.pm Revision Data ------------- Index: BOP.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/BOP.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -Llib/Parser/BOP.pm -Llib/Parser/BOP.pm -u -r1.14 -r1.15 --- lib/Parser/BOP.pm +++ lib/Parser/BOP.pm @@ -320,12 +320,17 @@ # sub perl { my $self= shift; my $parens = shift; - my $bop = $self->{def}; - my ($lparen,$rparen); if (!$bop->{isCommand}) {$lparen = 1; $rparen = 2} - my $perl = - $self->{lop}->perl($lparen). - (defined($bop->{perl}) ? $bop->{perl} : $bop->{string}). - $self->{rop}->perl($rparen); + my $bop = $self->{def}; my $perl; + if ($bop->{isCommand}) { + $perl = + ($bop->{perl} || ref($self).'->call'). + '('.$self->{lop}->perl.','.$self->{rop}->perl.')'; + } else { + $perl = + $self->{lop}->perl(1). + " ".($bop->{perl} || $bop->{string})." ". + $self->{rop}->perl(2); + } $perl = '('.$perl.')' if $parens; return $perl; } Index: Function.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/Function.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -Llib/Parser/Function.pm -Llib/Parser/Function.pm -u -r1.16 -r1.17 --- lib/Parser/Function.pm +++ lib/Parser/Function.pm @@ -284,7 +284,7 @@ my $fn = $self->{def}; my @p = (); my $perl; foreach my $x (@{$self->{params}}) {push(@p,$x->perl)} if ($fn->{perl}) {$perl = $fn->{perl}.'('.join(',',@p).')'} - else {return('(Parser::Function->call('.join(',',"'$self->{name}'",@p).'))')} + else {$perl = 'Parser::Function->call('.join(',',"'$self->{name}'",@p).')'} $perl = '('.$perl.')' if $parens == 1; return $perl; } Index: UOP.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/UOP.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -Llib/Parser/UOP.pm -Llib/Parser/UOP.pm -u -r1.14 -r1.15 --- lib/Parser/UOP.pm +++ lib/Parser/UOP.pm @@ -214,8 +214,12 @@ # sub perl { my $self = shift; my $parens = shift; - my $uop = $self->{def}; - my $perl = (defined($uop->{perl})? $uop->{perl}: $uop->{string}).$self->{op}->perl(1); + my $uop = $self->{def}; my $perl; + if ($uop->{isCommand}) { + $perl = ($uop->{perl} || ref($self).'->call').'('.$self->{op}->perl.')'; + } else { + $perl = ($uop->{perl} || $uop->{string})." ".$self->{op}->perl(1); + } $perl = '('.$perl.')' if $parens; return $perl; } Index: Default.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/Context/Default.pm,v retrieving revision 1.31 retrieving revision 1.32 diff -Llib/Parser/Context/Default.pm -Llib/Parser/Context/Default.pm -u -r1.31 -r1.32 --- lib/Parser/Context/Default.pm +++ lib/Parser/Context/Default.pm @@ -15,13 +15,13 @@ class => 'Parser::BOP::add'}, '-' => {precedence => 1, associativity => 'left', type => 'both', string => '-', - perl => '- ', class => 'Parser::BOP::subtract', rightparens => 'same'}, + class => 'Parser::BOP::subtract', rightparens => 'same'}, 'U' => {precedence => 1.5, associativity => 'left', type => 'bin', isUnion => 1, string => ' U ', TeX => '\cup ', class => 'Parser::BOP::union'}, '><'=> {precedence => 2, associativity => 'left', type => 'bin', - string => ' >< ', TeX => '\times ', perl => ' x ', fullparens => 1, + string => ' >< ', TeX => '\times ', perl => 'x', fullparens => 1, class => 'Parser::BOP::cross'}, '.' => {precedence => 2, associativity => 'left', type => 'bin', @@ -57,7 +57,7 @@ 'u+'=> {precedence => 6, associativity => 'left', type => 'unary', string => '+', class => 'Parser::UOP::plus', hidden => 1, allowInfinite => 1, nofractionparens => 1}, - 'u-'=> {precedence => 6, associativity => 'left', type => 'unary', string => '-', perl => '- ', + 'u-'=> {precedence => 6, associativity => 'left', type => 'unary', string => '-', class => 'Parser::UOP::minus', hidden => 1, allowInfinite => 1, nofractionparens => 1}, '^' => {precedence => 7, associativity => 'right', type => 'bin', string => '^', perl => '**', @@ -67,7 +67,7 @@ class => 'Parser::BOP::power', leftf => 1, fullparens => 1, isInverse => 1}, '!' => {precedence => 8, associativity => 'right', type => 'unary', string => '!', - class => 'Parser::UOP::factorial', perl => 'Factorial'}, + class => 'Parser::UOP::factorial', isCommand => 1}, '_' => {precedence => 9, associativity => 'left', type => 'bin', string => '_', class => 'Parser::BOP::underscore', leftparens => 'all'}, Index: factorial.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Parser/UOP/factorial.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -Llib/Parser/UOP/factorial.pm -Llib/Parser/UOP/factorial.pm -u -r1.4 -r1.5 --- lib/Parser/UOP/factorial.pm +++ lib/Parser/UOP/factorial.pm @@ -27,14 +27,6 @@ return $f; } -# -# Perl version uses Factorial() -# -sub perl { - my $self = shift; - return 'Factorial('.$self->{op}->perl.')'; -} - ######################################################################### # |