Skip to content

Commit

Permalink
Fixed the "help" command inside the REPL.
Browse files Browse the repository at this point in the history
  • Loading branch information
trizen committed Aug 26, 2023
1 parent 384eb06 commit efa54f1
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions bin/sidef
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,15 @@ sub read_script {
}

sub help_interactive {
my ($term) = @_;

require File::Spec;
require File::Basename;

require Encode;
require Term::ReadLine;

my $term = Term::ReadLine->new("$name $version -- help interactive mode");
$term //= Term::ReadLine->new("$name $version -- help interactive mode");

print <<"HELP";
Welcome to $name $version! This is the interactive help utility.
Expand Down Expand Up @@ -512,7 +513,7 @@ EOT
$line .= Encode::decode_utf8($term->readline($line eq '' ? '> ' : ' ') // return);

if ($line eq 'help') {
help_interactive();
help_interactive($term);
redo MAINLOOP;
}
elsif ($line eq '##') {
Expand Down Expand Up @@ -574,8 +575,7 @@ EOT
$vars = $copy_hash->($sidef->{parser}{vars});
$ref_vars_refs = $copy_hash->($sidef->{parser}{ref_vars_refs});

$line =~
s{#(-?[1-9][0-9]*)\b}{(abs($1) <= scalar(@values)) ? ('(' . $values[($1 < 0) ? $1 : $1-1]->{value} . ')') : "#$1"}ge;
$line =~ s{#(-?[1-9][0-9]*)\b}{(abs($1) <= scalar(@values)) ? ('(' . $values[($1 < 0) ? $1 : $1-1]->{value} . ')') : "#$1"}ge;

my $ccode = eval { $sidef->compile_code($line, $args{r} ? 'Sidef' : ($args{R} || 'Perl')) };

Expand Down Expand Up @@ -653,14 +653,8 @@ EOT
my $dump = join(
', ',
map {
(ref($_) ? UNIVERSAL::can($_, 'dump') ? $_->dump : $_ : ($_ // 'nil'))
. (
(
ref($_) eq 'Sidef::Types::Number::Number'
and ref($$_) eq 'Math::MPFR'
and Math::MPFR::Rmpfr_number_p($$_)
) ? 'f' : ''
)
(ref($_) ? UNIVERSAL::can($_, 'dump') ? $_->dump : $_ : ($_ // 'nil'))
. ((ref($_) eq 'Sidef::Types::Number::Number' and ref($$_) eq 'Math::MPFR' and Math::MPFR::Rmpfr_number_p($$_)) ? 'f' : '')
} @results
);

Expand Down

0 comments on commit efa54f1

Please sign in to comment.