Parser.Tokens.take doesn't return the accumulator acc in the base case, but always an empty array:
Tokens.take : Nat -> '{Tokens e t} () -> ([t], '{Tokens e t} ())
Tokens.take n input =
go acc loc n input =
use Nat ==
if n == 0 then ([], input)
else
handle !input
...
Parser.tokens doesn't make use of the passed comparison function equiv and thus accepting any string of the same length.
tokens : ([t] -> [t] -> Boolean) -> [t] -> Parser e t [t]
tokens equiv likeThis =
parse input =
match Throw.toEither '(Tokens.take (List.size likeThis) input) with
Left (TrivialError loc found _) ->
Throw.throw
(TrivialError loc found (base.Set.singleton (Tokens likeThis)))
Right (ts, rest) -> (ts, rest)
Parser parse
I've addressed both issues in the PR below. One difficulty I saw with using Tokens.take in the tokens function was that in case that equiv returned false we don't have access to the location where the parse error happened. I solved that by copying most of the structure of Tokens.take into the tokens function. Maybe you have a better solution.
The changes summarized below are available for you to review, using the following command:
I was experimenting with the parser library and run into the following problem:
Looking a bit deeper I found two issues:
Parser.Tokens.take doesn't return the accumulator
acc
in the base case, but always an empty array:Parser.tokens doesn't make use of the passed comparison function
equiv
and thus accepting any string of the same length.I've addressed both issues in the PR below. One difficulty I saw with using
Tokens.take
in thetokens
function was that in case thatequiv
returned false we don't have access to the location where the parse error happened. I solved that by copying most of the structure ofTokens.take
into thetokens
function. Maybe you have a better solution.The changes summarized below are available for you to review, using the following command:
Updates:
Added definitions: