2014-04-20 00:12:13 +04:00
|
|
|
use strict;
|
2014-04-22 05:08:18 +04:00
|
|
|
use warnings FATAL => qw(all);
|
2014-10-10 08:48:47 +04:00
|
|
|
no if $] >= 5.018, warnings => "experimental::smartmatch";
|
2014-05-11 01:03:25 +04:00
|
|
|
use File::Basename;
|
|
|
|
use lib dirname (__FILE__);
|
2014-12-19 05:33:49 +03:00
|
|
|
use readline qw(mal_readline set_rl_mode);
|
2014-04-20 00:12:13 +04:00
|
|
|
use feature qw(switch);
|
|
|
|
|
2014-04-21 08:45:58 +04:00
|
|
|
use reader;
|
|
|
|
use printer;
|
2014-04-20 00:12:13 +04:00
|
|
|
|
|
|
|
# read
|
|
|
|
sub READ {
|
|
|
|
my $str = shift;
|
2014-04-21 08:45:58 +04:00
|
|
|
return reader::read_str($str);
|
2014-04-20 00:12:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# eval
|
|
|
|
sub EVAL {
|
|
|
|
my($ast, $env) = @_;
|
|
|
|
return $ast;
|
|
|
|
}
|
|
|
|
|
|
|
|
# print
|
|
|
|
sub PRINT {
|
|
|
|
my $exp = shift;
|
2014-04-21 08:45:58 +04:00
|
|
|
return printer::_pr_str($exp);
|
2014-04-20 00:12:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# repl
|
|
|
|
sub REP {
|
|
|
|
my $str = shift;
|
|
|
|
return PRINT(EVAL(READ($str), {}));
|
|
|
|
}
|
|
|
|
|
2014-12-19 05:33:49 +03:00
|
|
|
if (scalar(@ARGV) > 0 && $ARGV[0] eq "--raw") {
|
|
|
|
set_rl_mode("raw");
|
|
|
|
}
|
2014-04-20 00:12:13 +04:00
|
|
|
while (1) {
|
2014-04-24 06:46:57 +04:00
|
|
|
my $line = mal_readline("user> ");
|
2014-04-20 00:12:13 +04:00
|
|
|
if (! defined $line) { last; }
|
2014-04-24 06:46:57 +04:00
|
|
|
do {
|
|
|
|
local $@;
|
|
|
|
my $ret;
|
|
|
|
eval {
|
|
|
|
use autodie; # always "throw" errors
|
|
|
|
print(REP($line), "\n");
|
|
|
|
1;
|
|
|
|
} or do {
|
|
|
|
my $err = $@;
|
|
|
|
given (ref $err) {
|
|
|
|
when (/^BlankException/) {
|
|
|
|
# ignore and continue
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
chomp $err;
|
|
|
|
print "Error: $err\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2014-04-20 00:12:13 +04:00
|
|
|
}
|