diff --git a/src/parz/combinators.gleam b/src/parz/combinators.gleam index 6bca6c9..19e45b5 100644 --- a/src/parz/combinators.gleam +++ b/src/parz/combinators.gleam @@ -91,15 +91,18 @@ pub fn maybe(parser) { } } -fn many_rec(parser: Parser(a), input, acc) { +fn many_rec( + parser: Parser(a), + input, + acc, +) -> Result(ParserState(List(a)), String) { case parser(input) { Error(err) -> Error(err) Ok(ok) -> { case many_rec(parser, ok.remaining, acc) { - Error(_) -> Ok(#([ok.matched], ok.remaining)) + Error(_) -> Ok(ParserState([ok.matched], ok.remaining)) Ok(rec) -> { - let #(matches, remaining) = rec - Ok(#([ok.matched, ..matches], remaining)) + Ok(ParserState([ok.matched, ..rec.matched], rec.remaining)) } } } @@ -113,7 +116,7 @@ pub fn many1(parser: Parser(a)) { pub fn many(parser: Parser(a)) { fn(input) { case many1(parser)(input) { - Error(_) -> Ok(#([], input)) + Error(_) -> Ok(ParserState([], input)) Ok(ok) -> Ok(ok) } } diff --git a/test/combinators_test.gleam b/test/combinators_test.gleam index 22d04fb..8ef1421 100644 --- a/test/combinators_test.gleam +++ b/test/combinators_test.gleam @@ -83,19 +83,19 @@ pub fn many_test() { run(parser, "!") |> should.be_ok - |> should.equal(#([], "!")) + |> should.equal(ParserState([], "!")) run(parser, "x") |> should.be_ok - |> should.equal(#(["x"], "")) + |> should.equal(ParserState(["x"], "")) run(parser, "xxx") |> should.be_ok - |> should.equal(#(["x", "x", "x"], "")) + |> should.equal(ParserState(["x", "x", "x"], "")) run(parser, "xx!") |> should.be_ok - |> should.equal(#(["x", "x"], "!")) + |> should.equal(ParserState(["x", "x"], "!")) } pub fn many1_test() { @@ -106,15 +106,15 @@ pub fn many1_test() { run(parser, "x") |> should.be_ok - |> should.equal(#(["x"], "")) + |> should.equal(ParserState(["x"], "")) run(parser, "xxx") |> should.be_ok - |> should.equal(#(["x", "x", "x"], "")) + |> should.equal(ParserState(["x", "x", "x"], "")) run(parser, "xx!") |> should.be_ok - |> should.equal(#(["x", "x"], "!")) + |> should.equal(ParserState(["x", "x"], "!")) } pub fn sequence_test() {