-module(yamleam@decoder). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/yamleam/decoder.gleam"). -export([to_dynamic/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Bridge from `YamlNode` to `gleam/dynamic` so that the stdlib\n" " `gleam/dynamic/decode` decoders work over a parsed YAML tree.\n" "\n" " The conversion is straightforward because the Erlang term shapes\n" " produced by `dynamic.from` for Gleam primitives match what the\n" " stdlib decoders expect:\n" "\n" " | YAML | Gleam | Erlang |\n" " |---|---|---|\n" " | YamlNull | Nil | nil atom |\n" " | YamlBool | Bool | true / false atom |\n" " | YamlInt | Int | integer |\n" " | YamlFloat | Float | float |\n" " | YamlString | String | binary |\n" " | YamlList | List(Dynamic) | list |\n" " | YamlMap | Dict(String, Dynamic) | map |\n" ). -file("src/yamleam/decoder.gleam", 25). -spec to_dynamic(yamleam@node:yaml_node()) -> gleam@dynamic:dynamic_(). to_dynamic(N) -> case N of yaml_null -> gleam@dynamic:nil(); {yaml_bool, B} -> gleam_stdlib:identity(B); {yaml_int, I} -> gleam_stdlib:identity(I); {yaml_float, F} -> gleam_stdlib:identity(F); {yaml_string, S} -> gleam_stdlib:identity(S); {yaml_list, Items} -> _pipe = Items, _pipe@1 = gleam@list:map(_pipe, fun to_dynamic/1), gleam_stdlib:identity(_pipe@1); {yaml_map, Pairs} -> _pipe@2 = Pairs, _pipe@3 = gleam@list:map( _pipe@2, fun(Pair) -> {Key, Value} = Pair, {gleam_stdlib:identity(Key), to_dynamic(Value)} end ), gleam@dynamic:properties(_pipe@3) end.