aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/adglent/src/priv/toml.gleam
diff options
context:
space:
mode:
authorJ.J <thechairman@thechairman.info>2024-05-30 21:50:02 -0400
committerJ.J <thechairman@thechairman.info>2024-05-30 21:50:02 -0400
commit612fd986ab1e00b6d34dc1937136250e08e89325 (patch)
treea3c93952040c6afdf348b5831619a45db7ba0a2e /aoc2023/build/packages/adglent/src/priv/toml.gleam
parent231c2b688d1e6cf0846d46e883da30e042a9c6cf (diff)
downloadgleam_aoc-612fd986ab1e00b6d34dc1937136250e08e89325.tar.gz
gleam_aoc-612fd986ab1e00b6d34dc1937136250e08e89325.zip
cleanup
Diffstat (limited to 'aoc2023/build/packages/adglent/src/priv/toml.gleam')
-rw-r--r--aoc2023/build/packages/adglent/src/priv/toml.gleam52
1 files changed, 52 insertions, 0 deletions
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)
+}