Parsing release v10.1.0 -- stuff I stole from Elm

I just released Release v10.1.0 · purescript-contrib/purescript-parsing · GitHub and I like this one.

@MaybeJustJames asked me a question during my PureConf talk last year about recursive monadic parsing and strict evaluation in PureScript and I didn’t have a good answer for that question. I think @MaybeJustJames was probably expecting this answer. I have a better answer now, and I put it on the Parsing README under Recursion.

There is a new parseErrorHuman function. I stole the idea from Elm. I mean, this idea is kind of obvious, like a lot of stuff in Elm, it’s so obviously useful and right that I’m embarrassed that I didn’t think it up myself.

I also added some docs showing how to make an inContext function which is also kind of stolen from Elm.

6 Likes

In the docs for recursion:

aye :: Parser String Char
aye = do
  char 'a'
  aye

This would not trigger that error. It triggers an unrelated error due to disarding char. In any case, this would desugar to:

aye = discard (char 'a') \_ -> aye

Which is guarded under a lambda. In fact, any monadic recursion on the right-hand-side of a desugared bind will compile successfully. If it was written instead as:

aye = char 'a' *> aye

It would better illustrate your point as this runs afoul the recursive check.

1 Like

Amazing work @jamesbrock ! I’m excited to try this one out :smiley:

1 Like

In the docs for recursion:
This would not trigger that error.

Thx! Changed.

A bit creepy how you called your function for good error messages given that I recently write this one

https://pursuit.purescript.org/packages/purescript-yoga-json/4.0.1/docs/Yoga.JSON.Error#v:renderHumanError

1 Like