stchang / parsack

A basic Parsec-like monadic parser combinator library implementation in Racket.
MIT License
50 stars 10 forks source link

parse should return actual parse result instead of Consumed #7

Closed stchang closed 10 years ago

greghendershott commented 10 years ago

This did seem weird to me at first; in my app I ended up defining a parse-result function. However, the status quo parse very useful when debugging parsers. Especially getting the returned new State: Did my parser proceed too far? You can't always tell that from the result, because a parser doesn't always return everything it consumes.

So I suggest keeping parse as-is, but adding a parse-result function. How I did it:

(define (parse-result p s)
  (match (parse p s)
    [(Consumed! (Ok parsed _ _)) parsed]
    [x (error 'parse-result (~v x))]))

If this looks OK (?) let me know whether you want me to make the change or you will?

stchang commented 10 years ago

I was going to change parse to essentially be what you wrote, but you make a good point regarding debugging, so I'm onboard with leaving as is and adding parse-result.

If it's convenient, can you just push the change? Otherwise I'll get to it maybe tonight or this weekend.