From 96a3c5c179d8d3fff24eb2953e45f8dd15e2714c Mon Sep 17 00:00:00 2001 From: HJ Date: Sat, 3 Feb 2024 15:09:54 -0500 Subject: cleanup --- aoc2023/build/packages/adglent/src/priv/toml.gleam | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 aoc2023/build/packages/adglent/src/priv/toml.gleam (limited to 'aoc2023/build/packages/adglent/src/priv/toml.gleam') diff --git a/aoc2023/build/packages/adglent/src/priv/toml.gleam b/aoc2023/build/packages/adglent/src/priv/toml.gleam new file mode 100644 index 0000000..7042833 --- /dev/null +++ b/aoc2023/build/packages/adglent/src/priv/toml.gleam @@ -0,0 +1,52 @@ +import tom +import gleam/result + +pub type TomError { + TomParseError(error: tom.ParseError) + TomGetError(error: tom.GetError) +} + +pub fn get_string( + toml_content: String, + key_path: List(String), +) -> Result(String, TomError) { + use toml <- result.try( + tom.parse(toml_content <> "\n") + |> result.map_error(TomParseError), + ) + use value <- result.try( + tom.get_string(toml, key_path) + |> result.map_error(TomGetError), + ) + Ok(value) +} + +pub fn get_bool( + toml_content: String, + key_path: List(String), +) -> Result(Bool, TomError) { + use toml <- result.try( + tom.parse(toml_content <> "\n") + |> result.map_error(TomParseError), + ) + use value <- result.try( + tom.get_bool(toml, key_path) + |> result.map_error(TomGetError), + ) + Ok(value) +} + +pub fn get_int( + toml_content: String, + key_path: List(String), +) -> Result(Int, TomError) { + use toml <- result.try( + tom.parse(toml_content <> "\n") + |> result.map_error(TomParseError), + ) + use value <- result.try( + tom.get_int(toml, key_path) + |> result.map_error(TomGetError), + ) + Ok(value) +} -- cgit v1.2.3