aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/adglent/src/priv@toml.erl
diff options
context:
space:
mode:
authorHJ <thechairman@thechairman.info>2024-02-03 15:09:54 -0500
committerHJ <thechairman@thechairman.info>2024-02-03 15:09:54 -0500
commit96a3c5c179d8d3fff24eb2953e45f8dd15e2714c (patch)
tree0a67bc0cfeabe51740bb049c61f16f1ac3bdd4ff /aoc2023/build/packages/adglent/src/priv@toml.erl
parent547fe03cf43105f46160e2dd9afff21637eaaf47 (diff)
downloadgleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.tar.gz
gleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.zip
cleanup
Diffstat (limited to 'aoc2023/build/packages/adglent/src/priv@toml.erl')
-rw-r--r--aoc2023/build/packages/adglent/src/priv@toml.erl83
1 files changed, 83 insertions, 0 deletions
diff --git a/aoc2023/build/packages/adglent/src/priv@toml.erl b/aoc2023/build/packages/adglent/src/priv@toml.erl
new file mode 100644
index 0000000..6c41fbf
--- /dev/null
+++ b/aoc2023/build/packages/adglent/src/priv@toml.erl
@@ -0,0 +1,83 @@
+-module(priv@toml).
+-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
+
+-export([get_string/2, get_bool/2, get_int/2]).
+-export_type([tom_error/0]).
+
+-type tom_error() :: {tom_parse_error, tom:parse_error()} |
+ {tom_get_error, tom:get_error()}.
+
+-spec get_string(binary(), list(binary())) -> {ok, binary()} |
+ {error, tom_error()}.
+get_string(Toml_content, Key_path) ->
+ gleam@result:'try'(
+ begin
+ _pipe = tom:parse(<<Toml_content/binary, "\n"/utf8>>),
+ gleam@result:map_error(
+ _pipe,
+ fun(Field@0) -> {tom_parse_error, Field@0} end
+ )
+ end,
+ fun(Toml) ->
+ gleam@result:'try'(
+ begin
+ _pipe@1 = tom:get_string(Toml, Key_path),
+ gleam@result:map_error(
+ _pipe@1,
+ fun(Field@0) -> {tom_get_error, Field@0} end
+ )
+ end,
+ fun(Value) -> {ok, Value} end
+ )
+ end
+ ).
+
+-spec get_bool(binary(), list(binary())) -> {ok, boolean()} |
+ {error, tom_error()}.
+get_bool(Toml_content, Key_path) ->
+ gleam@result:'try'(
+ begin
+ _pipe = tom:parse(<<Toml_content/binary, "\n"/utf8>>),
+ gleam@result:map_error(
+ _pipe,
+ fun(Field@0) -> {tom_parse_error, Field@0} end
+ )
+ end,
+ fun(Toml) ->
+ gleam@result:'try'(
+ begin
+ _pipe@1 = tom:get_bool(Toml, Key_path),
+ gleam@result:map_error(
+ _pipe@1,
+ fun(Field@0) -> {tom_get_error, Field@0} end
+ )
+ end,
+ fun(Value) -> {ok, Value} end
+ )
+ end
+ ).
+
+-spec get_int(binary(), list(binary())) -> {ok, integer()} |
+ {error, tom_error()}.
+get_int(Toml_content, Key_path) ->
+ gleam@result:'try'(
+ begin
+ _pipe = tom:parse(<<Toml_content/binary, "\n"/utf8>>),
+ gleam@result:map_error(
+ _pipe,
+ fun(Field@0) -> {tom_parse_error, Field@0} end
+ )
+ end,
+ fun(Toml) ->
+ gleam@result:'try'(
+ begin
+ _pipe@1 = tom:get_int(Toml, Key_path),
+ gleam@result:map_error(
+ _pipe@1,
+ fun(Field@0) -> {tom_get_error, Field@0} end
+ )
+ end,
+ fun(Value) -> {ok, Value} end
+ )
+ end
+ ).