diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-12-21 22:09:25 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-12-21 22:09:25 +0100 |
commit | d8e183f02f67522d94deafa328e19b3081ca41be (patch) | |
tree | 4617cc4fec15365cdcdfeb594b02432937d6c946 /aoc-2020-gleam/src/util/parser.gleam | |
parent | 02598d252c0e9093384ec53e46445df1a783feda (diff) | |
download | gleam_aoc2020-d8e183f02f67522d94deafa328e19b3081ca41be.tar.gz gleam_aoc2020-d8e183f02f67522d94deafa328e19b3081ca41be.zip |
Update to newest Gleam version
Diffstat (limited to 'aoc-2020-gleam/src/util/parser.gleam')
-rw-r--r-- | aoc-2020-gleam/src/util/parser.gleam | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/aoc-2020-gleam/src/util/parser.gleam b/aoc-2020-gleam/src/util/parser.gleam index 1d4bba9..3b2e20e 100644 --- a/aoc-2020-gleam/src/util/parser.gleam +++ b/aoc-2020-gleam/src/util/parser.gleam @@ -5,7 +5,7 @@ import gleam/bool import gleam/string as str import gleam/result as res import gleam/function as fun -import gleam/option.{None, Option, Some} as opt +import gleam/option.{None, type Option, Some} // Heavily inspired by https://fsharpforfunandprofit.com/posts/understanding-parser-combinators/ @@ -188,19 +188,19 @@ pub fn then_3rd(two: Parser(#(a, b)), third: Parser(c)) -> Parser(#(a, b, c)) { }) } -pub fn or(first: Parser(a), else second: Parser(a)) -> Parser(a) { +pub fn or(first: Parser(a), otherwise second: Parser(a)) -> Parser(a) { create(fn(input) { first |> run(on: input) |> res.or(run(second, on: input)) }) - |> labeled(with: first.label <> " |> or(else: " <> second.label <> ")") + |> labeled(with: first.label <> " |> or(otherwise: " <> second.label <> ")") } pub fn opt(parser: Parser(a)) -> Parser(Option(a)) { parser |> map(with: Some) - |> or(else: succeeding(with: None)) + |> or(otherwise: succeeding(with: None)) |> labeled(with: "opt(" <> parser.label <> ")") } @@ -340,7 +340,7 @@ pub fn sep1(parser: Parser(a), by separator: Parser(b)) -> Parser(List(a)) { pub fn sep0(parser: Parser(a), by separator: Parser(b)) -> Parser(List(a)) { parser |> sep1(by: separator) - |> or(else: succeeding(with: [])) + |> or(otherwise: succeeding(with: [])) |> labeled( with: "sep0(" <> parser.label <> ", by: " <> separator.label <> ")", ) |