Changeset 183

Show
Ignore:
Timestamp:
11/11/04 01:31:46 (4 years ago)
Author:
svn
Message:

Question mark can now be inserted into string bodies, and unbalanced strings
are checked for.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • manage/trunk/CLI.pm

    r182 r183  
    347347        for my $tok (@intok) { 
    348348                if (defined($tok) and $tok !~ /^\s*$/) { 
    349                         if ($tok =~ /$self->{stringpattern}/) { 
    350                         my $error = undef; 
    351  
    352                                 $SIG{__WARN__} = sub { $error = $_[0]; }; 
    353                                 $tok = eval "$tok"; 
    354                                 $SIG{__WARN__} = 'DEFAULT'; 
    355                                 return ('ERROR', 'Invalid string.') if $@; 
    356                                 chomp($error), $error =~ s/at \(eval\).*//, return ('ERROR', $error) if defined($error); 
     349                        # Special case to detect malformed strings 
     350                        if ($tok =~ /^['"]/) { 
     351                                if ($tok =~ /$self->{stringpattern}/) { 
     352                                my $error = undef; 
     353 
     354                                        $SIG{__WARN__} = sub { $error = $_[0]; }; 
     355                                        $tok = eval "$tok"; 
     356                                        $SIG{__WARN__} = 'DEFAULT'; 
     357                                        return ('ERROR', "Invalid string '$tok'.") if $@; 
     358                                        chomp($error), $error =~ s/at \(eval\).*//, return ('ERROR', $error) if defined($error); 
     359                                } else { 
     360                                        return ('ERROR', "Invalid string '$tok'."); 
     361                                } 
    357362                        } 
    358363                        push(@tokens, $tok); 
  • manage/trunk/manage

    r178 r183  
    220220                $action->($ctx, @{$ctx->args()}); 
    221221        } elsif ($type eq 'ERROR') { 
    222         my @gh = @{$ctx->grammar_history()}; 
    223         my @th = @{$ctx->token_history()}; 
    224         my @ath = @{$ctx->all_tokens()}; 
    225         my $grammar = $gh[$#gh]; 
    226         my @candidates; 
    227                 push(@th, "") if $action =~ /More input expected/; 
    228         my $prefix = ' ' x length("@th[0 .. $#th - 1]") . (@th <= @ath ? ' ' : ''); 
    229  
    230                 $action = "$C{underline}@ath$C{nounderline}\n    $prefix^ $action"; 
    231                 for my $key (keys(%{$gh[$#gh]})) { 
    232                 my $cmd = $key; 
    233                 my $type = ref($grammar->{$key}); 
    234  
    235                         next if $cmd =~ /^[A-Z]+$/; 
    236                         $cmd =~ s/^(\d+\))?(\$(\*)?)?//; 
    237                         if ($type eq 'HASH' and $grammar->{$key}->{HELP}) { 
    238                                 $type = ref($grammar->{$key}->{HELP}); 
    239                                 if ($type eq 'ARRAY') { 
    240                                         $cmd = $grammar->{$key}->{HELP}->[0]; 
    241                                 } elsif ($type eq 'CODE') { 
    242                                 my %s = $grammar->{$key}->{HELP}->($ctx, @{$ctx->args()}); 
    243                                         push(@candidates, keys(%s)); 
    244                                         $cmd = undef; 
     222                if (defined($ctx)) { 
     223                my @gh = @{$ctx->grammar_history()}; 
     224                my @th = @{$ctx->token_history()}; 
     225                my @ath = @{$ctx->all_tokens()}; 
     226                my $grammar = $gh[$#gh]; 
     227                my @candidates; 
     228                        push(@th, "") if $action =~ /More input expected/; 
     229                my $prefix = ' ' x length("@th[0 .. $#th - 1]") . (@th <= @ath ? ' ' : ''); 
     230 
     231                        $action = "$C{underline}@ath$C{nounderline}\n    $prefix^ $action"; 
     232                        for my $key (keys(%{$gh[$#gh]})) { 
     233                        my $cmd = $key; 
     234                        my $type = ref($grammar->{$key}); 
     235 
     236                                next if $cmd =~ /^[A-Z]+$/; 
     237                                $cmd =~ s/^(\d+\))?(\$(\*)?)?//; 
     238                                if ($type eq 'HASH' and $grammar->{$key}->{HELP}) { 
     239                                        $type = ref($grammar->{$key}->{HELP}); 
     240                                        if ($type eq 'ARRAY') { 
     241                                                $cmd = $grammar->{$key}->{HELP}->[0]; 
     242                                        } elsif ($type eq 'CODE') { 
     243                                        my %s = $grammar->{$key}->{HELP}->($ctx, @{$ctx->args()}); 
     244                                                push(@candidates, keys(%s)); 
     245                                                $cmd = undef; 
     246                                        } 
     247                                } 
     248                                if (defined($cmd)) { 
     249                                        push(@candidates, $cmd); 
    245250                                } 
    246251                        } 
    247                         if (defined($cmd)) { 
    248                                 push(@candidates, $cmd); 
     252                        if (@candidates and $grammar->{ACTION}) { 
     253                                push(@candidates, "<eol>"); 
    249254                        } 
    250                 } 
    251                 if (@candidates and $grammar->{ACTION}) { 
    252                         push(@candidates, "<eol>"); 
    253                 } 
    254                 @candidates = sort(@candidates); 
    255                 if (@candidates > 1) { 
    256                         $action .= "\n    ${prefix}Candidates are " . join(", ", @candidates[0 .. $#candidates - 1]) . " and " . $candidates[-1] . "."; 
    257                 } elsif (@candidates == 1) { 
    258                         $action .= "\n    ${prefix}Expecting @candidates."; 
    259                 } else { 
    260                         if ($grammar->{ACTION}) { 
    261                                 $action .= "\n    ${prefix}Expected end of command."; 
    262 #                       } else { 
    263 #                               $action .= "\n    ${prefix}Can't find any candidates, probably a grammar error." 
     255                        @candidates = sort(@candidates); 
     256                        if (@candidates > 1) { 
     257                                $action .= "\n    ${prefix}Candidates are " . join(", ", @candidates[0 .. $#candidates - 1]) . " and " . $candidates[-1] . "."; 
     258                        } elsif (@candidates == 1) { 
     259                                $action .= "\n    ${prefix}Expecting @candidates."; 
     260                        } else { 
     261                                if ($grammar->{ACTION}) { 
     262                                        $action .= "\n    ${prefix}Expected end of command."; 
     263                                } 
    264264                        } 
    265265                } 
     
    424424                print("\n$action"); 
    425425                $term->forced_update_display(); 
     426        } else { 
     427                $term->insert_text('?'); 
    426428        } 
    427429}, ord('?'));