[ number => qr/([\d.]+)/ ],
[ string => qr/'(.*)'/s ],
[ bool => qr/(true|false)/ ],
- [ symbol => qr/([a-zA-Z_][a-zA-Z0-9_]*)/ ],
+ # foo or Foo or ?Foo or _Foo or ?_Foo
+ [ symbol => qr/((?:[a-z]|\??[A-Z_])[a-zA-Z0-9_]*)/ ],
[ dict => qr/{(.*)}/s ],
[ array => qr/\[(.*)\]/s ],
);
use Tcl;
use Scalar::Util qw(weaken);
use DX::Expander;
+use DX::Proposition;
+use DX::Utils qw(deparse);
use DX::Class;
has shell_state => (is => 'rwp', required => 1, isa => ShellState);
$tcl->CreateCommand('.' => sub {
$self->apply_to_state([ mode => 'shell' ])
});
+ $tcl->CreateCommand(qlist => sub {
+ push our @Result, map [ output => $_ ], @{
+ $self->shell_state->current_query_state->proposition_sequence->members
+ };
+ return;
+ });
foreach my $pred (
keys %{$self->shell_state->template_query_state->predicates}
) {
} catch {
push @Result, [ output => $_ ];
};
- return @Result;
+ return map {
+ ($_->[0] eq 'output' and ref($_->[1]))
+ ? [ output => deparse($_->[1]) ]
+ : $_
+ } @Result;
}
sub apply_predicate {
- my ($self, $pred, @args) = @_;
+ my ($self, $pred, @arg_strings) = @_;
die "Can't call predicate ${pred} outside a query\n"
unless $self->shell_state->mode eq 'query';
-use Data::Dumper::Concise; die Dumper [ $pred, $self->expand_args(@args) ];
+ my @args = $self->expand_args(@arg_strings);
+ my $intro; my $need;
+ foreach my $arg (@args) {
+ next if ref($arg);
+ # ?Foo is intro, Foo is need
+ ($arg =~ s/^\?// ? $intro : $need)->{$arg} = 1;
+ }
+ my $prop = DX::Proposition->new(
+ predicate => $pred,
+ args => \@args,
+ introduces_names => $intro,
+ requires_names => $need,
+ );
+ my $qstate = $self->shell_state->current_query_state;
+ $qstate = $qstate->but(
+ proposition_sequence => $qstate->proposition_sequence
+ ->but_append_proposition($prop)
+ );
+ $self->_set_shell_state(
+ $self->shell_state->but(
+ current_query_state => $qstate
+ )
+ );
+ return;
}
1;