make protoshell handle errors
[scpubgit/DX.git] / bin / protoshell
CommitLineData
88eac4d2 1use strictures 2;
2use Module::Runtime qw(use_module);
3use DX::Utils qw(dict deparse);
4use Devel::Dwarn;
03fafee9 5use Try::Tiny;
88eac4d2 6BEGIN { *u = \&use_module }
7
8my $scope = u('DX::Scope')->new(
9 predicates => {
10 map +(
11 $_ => u('DX::Predicate::'.join('', map ucfirst, split '_', $_))->new
12 ), qw(eq member_at is_dict)
13 },
14 globals => dict(),
15 locals => [],
16);
17
18my $exp = u('DX::Expander')->new;
19
20my $tcl = u('Tcl')->new;
21
22foreach my $pred (keys %{$scope->predicates}) {
23 $tcl->CreateCommand($pred => sub {
24 my (undef, undef, undef, @args) = @_;
25 Dwarn [ $pred, $exp->expand_args(@args) ];
26 });
27}
28
29my $rl = u('Caroline')->new;
30
31while (my $line = $rl->readline('$ ')) {
03fafee9 32 try {
33 $tcl->Eval($line);
34 } catch {
35 warn "Eval error: $_";
36 };
37 $rl->history_add($line);
88eac4d2 38}