-module(repr). -compile([no_auto_import, nowarn_unused_vars]). -export([object_repr/1, print/1]). -spec datatype_repr(dtype:gloom_type()) -> binary(). datatype_repr(Datatype) -> case Datatype of number -> <<"number"/utf8>>; string -> <<"string"/utf8>>; table -> <<"table"/utf8>> end. -spec affinity_repr(affinity:gloom_affinity()) -> binary(). affinity_repr(Affinity) -> case Affinity of nothing -> <<"Nothing"/utf8>>; everything -> <<"Everything"/utf8>>; something -> <<"Something"/utf8>> end. -spec value_repr(gleam_value:gleam_value()) -> binary(). value_repr(Gloom_value) -> case Gloom_value of {int_value, Value} -> gleam@int:to_string(Value); {float_value, Value@1} -> gleam@float:to_string(Value@1); {string_value, Value@2} -> <<<<"'"/utf8, Value@2/binary>>/binary, "'"/utf8>>; {map_value, Value@3} -> gloom_table_list_repr(Value@3); {object_value, Value@4} -> object_repr(Value@4) end. -spec gloom_table_list_repr( gleam@map:map_(gleam_value:gleam_value(), gleam_value:gleam_value()) ) -> binary(). gloom_table_list_repr(Table) -> Key_value_repr = fun(Item) -> {Key, Value} = Item, _pipe = gleam@string_builder:from_string(value_repr(Key)), _pipe@1 = gleam@string_builder:append(_pipe, <<" =>"/utf8>>), _pipe@2 = gleam@string_builder:append(_pipe@1, value_repr(Value)), gleam@string_builder:append(_pipe@2, <<"\n"/utf8>>) end, _pipe@3 = Table, _pipe@4 = gleam@map:to_list(_pipe@3), _pipe@5 = gleam@list:map(_pipe@4, Key_value_repr), _pipe@6 = gleam@string_builder:concat(_pipe@5), gleam@string_builder:to_string(_pipe@6). -spec object_repr(gleam_value:gloom_object()) -> binary(). object_repr(Object) -> case erlang:element(3, Object) of table -> Len = gleam_value:length(erlang:element(5, Object)), Header_template = <<"\n({affinity} {datatype} containing {length} elements):\n \n {value}"/utf8>>, template:template_replace_all( Header_template, gleam@map:from_list( [{<<"value"/utf8>>, value_repr(erlang:element(5, Object))}, {<<"datatype"/utf8>>, datatype_repr(erlang:element(3, Object))}, {<<"affinity"/utf8>>, affinity_repr(erlang:element(4, Object))}, {<<"length"/utf8>>, gleam@int:to_string(Len)}] ) ); _ -> Header_template@1 = <<"\t{value}:{affinity} "/utf8>>, template:template_replace_all( Header_template@1, gleam@map:from_list( [{<<"value"/utf8>>, value_repr(erlang:element(5, Object))}, {<<"datatype"/utf8>>, datatype_repr(erlang:element(3, Object))}, {<<"affinity"/utf8>>, affinity_repr(erlang:element(4, Object))}] ) ) end. -spec print(gleam_value:gloom_object()) -> nil. print(Object) -> _pipe = Object, _pipe@1 = object_repr(_pipe), gleam@io:println(_pipe@1).