sub _fmt {
my ($self, $thing, $meta) = @_;
return $thing unless ref($thing);
- my $type = join'_', split '::', lc +(ref($thing) =~ /^DX::(.*)/)[0];
+ my $type = join'_', split '::', lc +(ref($thing) =~ /^(?:DX::)?(.*)/)[0];
$self->${\"_fmt_${type}"}($thing, $meta);
}
sub _fmt_value_dict {
- my ($self, $dict, $ometa) = @_;
- my $imeta = $self->_inner_meta($ometa);
- my $chunks = $self->_indent_one(join "\n", map {
- "$_ ".$self->_fmt($dict->get_member_at($_), $imeta)
- } $dict->index_list);
+ my ($self, $dict, $meta) = @_;
+ my $chunks = $self->_fmt_pairs([
+ map [ $_, $dict->get_member_at($_) ], $dict->index_list
+ ], $meta);
+ return '{{ }}' unless $chunks =~ /\S/;
"{{\n${chunks}\n}}";
}
+sub _fmt_pairs {
+ my ($self, $pairs, $ometa) = @_;
+ my $imeta = $self->_inner_meta($ometa);
+ $self->_indent_one(join "\n", map {
+ join ' ', map $self->_fmt($_, $imeta), @$_
+ } @$pairs);
+}
+
sub _fmt_value_string {
my ($self, $string) = @_;
+ # TODO: multiline handling
my $val = $string->string_value;
if ($val =~ /^\w+$/) {
qq{'${val}'}
sub _fmt_value_false { 'false' }
-sub _fmat_value_unset { 'unset' }
+sub _fmt_value_unset { 'unset' }
+
+sub _fmt_object {
+ my ($self, $pairs, $meta) = @_;
+ my $chunks = $self->_fmt_pairs($pairs, $meta);
+ return '{ }' unless $chunks =~ /\S/;
+ "{\n${chunks}\n}"
+}
+
+sub _fmt_hypothesis {
+ my ($self, $hyp, $meta) = @_;
+ $self->_fmt_object([
+ map [ $_ => $hyp->$_ ],
+ qw(actions outstanding_propositions resolved_propositions scope)
+ ], $meta);
+}
+
+sub _fmt_array {
+ my ($self, $ary, $ometa) = @_;
+ my $imeta = $self->_inner_meta($ometa);
+ my $chunks = $self->_indent_one(
+ join "\n", map $self->_fmt($_, $imeta), @$ary
+ );
+ return '{ }' unless $chunks =~ /\S/;
+ "{\n${chunks}\n}";
+}
+
+sub _fmt_action_setvalue {
+ my ($self, $action, $meta) = @_;
+ $self->_fmt_action_generic(SetValue => $action, $meta);
+}
+
+sub _fmt_action_addvalue {
+ my ($self, $action, $meta) = @_;
+ $self->_fmt_action_generic(AddValue => $action, $meta);
+}
+
+sub _fmt_action_generic {
+ my ($self, $name, $action, $meta) = @_;
+ my $path = join '.', map $self->_fmt($_, $meta), @{$action->target_path};
+ join ' ', $name, $path, $self->_fmt($action->new_value, $meta);
+}
+
+sub _fmt_resolvedpropositionset { '{...}' }
+
+sub _fmt_scope {
+ my ($self, $scope, $meta) = @_;
+ $self->_fmt_object([
+ [ W => $scope->globals ],
+ map [ $_ => $scope->locals->[$_] ], 0..$#{$scope->locals}
+ ], $meta);
+}
+
+sub _fmt_searchstate {
+ my ($self, $ss, $meta) = @_;
+ $self->_fmt_object([
+ [ alternatives => '{...}' ],
+ [ current_hypothesis => $ss->current_hypothesis ],
+ ], $meta);
+}
1;