From b1c7707fcbfebd67ad2913fe96a27c73e4104af5 Mon Sep 17 00:00:00 2001 From: Will Coleda Date: Fri, 4 Dec 2009 15:39:57 -0500 Subject: [PATCH] empty expression should error. --- TODO | 6 ------ src/Partcl/commands/main.pm | 28 ++++++++++++++++------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/TODO b/TODO index 8e71fbc..cbd5ee4 100644 --- a/TODO +++ b/TODO @@ -4,12 +4,6 @@ Big Goals Tasks/Bugs: -* empty expr should die: - -% expr "" -empty expression -in expression "" - * regexp $re $str (blocker for t/tcl_time.t) * regsub -all * Need to throw an exception when trying to convert something to an diff --git a/src/Partcl/commands/main.pm b/src/Partcl/commands/main.pm index 0cfc691..2c31975 100644 --- a/src/Partcl/commands/main.pm +++ b/src/Partcl/commands/main.pm @@ -118,19 +118,23 @@ our sub exit(*@args) { our sub expr(*@args) { my $code := pir::join(' ', @args); - our %EXPRCACHE; - my &sub := %EXPRCACHE{$code}; - unless pir::defined__IP(&sub) { - my $parse := - Partcl::Grammar.parse( - $code, - :rule('TOP_expr'), - :actions(Partcl::Actions) - ); - &sub := PAST::Compiler.compile($parse.ast); - %EXPRCACHE{$code} := ⊂ + if $code ne '' { + our %EXPRCACHE; + my &sub := %EXPRCACHE{$code}; + unless pir::defined__IP(&sub) { + my $parse := + Partcl::Grammar.parse( + $code, + :rule('TOP_expr'), + :actions(Partcl::Actions) + ); + &sub := PAST::Compiler.compile($parse.ast); + %EXPRCACHE{$code} := ⊂ + } + &sub(); + } else { + error("empty expression\nin expression \"\""); } - &sub(); } our sub for(*@args) {