# \[ANN\] reparse 2.0.0

**URL:** <https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868>\
**Category:** Community\
**Tags:** announce, parsing\
**Created:** [November 28, 2020, 3:40pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868 "2020-11-28T15:40:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [November 28, 2020, 3:40pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/1 "2020-11-28T15:40:51Z")

</div>

A new version of `reparse` 2.0.0 has been released to opam.

Reparse is a monadic, recursive descent based, comprehensive, parser construction library for ocaml.

##### CHANGES for version 2.0.0:

- Rewrite the whole package to use exceptions rather than `result` type
- Adds many more parsing combinators
- Adds comprehensive unit tests
- Adds comprehensive documentation, host documentation and add links in repo home page
- Adds abstraction for input source
- Provides unix file source and string input source
- Adds separate package `reparse-unix` for unix file input
- Adds calc.ml and json.ml in examples.

Additionally, the API is now comprehensively documented with at least an example for each API call.

- [Github Reparse](https://github.com/lemaetech/reparse)
- [API Docs](https://lemaetech.co.uk/reparse/)

Enjoy.

B.

---

<div class="post-metadata">

**Author:** ![rixed](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rixed/32/56_2.png) [@rixed](https://discuss.ocaml.org/u/rixed)\
**Post date:** [December 1, 2020, 9:29am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/2 "2020-12-01T09:29:47Z")

</div>

> [@BikalGurung](#):
>
> Rewrite the whole package to use exceptions rather than `result` type

I’d like to know the rational behind this change. Would you have time to comment?

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [December 1, 2020, 11:47am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/3 "2020-12-01T11:47:31Z")

</div>

Ah, yes. It’s been a while since I made the decision so let me recollect a bit. I will most likely write a blog post and post it here. Stay tuned.

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [December 2, 2020, 3:11pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/4 "2020-12-02T15:11:01Z")

</div>

How does this compare with Angstrom, which is also a parser combinator library? It supports parsing binary formats but it works for text formats as well.

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [December 2, 2020, 9:47pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/5 "2020-12-02T21:47:58Z")

</div>

> [@lindig](#):
>
> How does this compare with Angstrom,

Apologies, I haven’t used Angstrom yet to be able to comment on it.

---

<div class="post-metadata">

**Author:** ![cemerick](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cemerick/32/1383_2.png) [@cemerick](https://discuss.ocaml.org/u/cemerick)\
**Post date:** [December 3, 2020, 5:01am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/6 "2020-12-03T05:01:51Z")

</div>

> [@BikalGurung](#):
>
> Apologies, I haven’t used Angstrom yet to be able to comment on it.

I use angstrom extensively, so I’ll definitely be taking a look at reparse. It’s a pity you weren’t aware of angstrom prior to starting work on it; of course, being familiar with prior work can often usefully inform one’s own.

I wonder if this library is something you wanted to build and share regardless, or if you had unsuccessfully looked for something like it previously? Despite good work in the community, discovering appropriate libraries can still be a bit of a challenge sometimes compared to fuller ecosystems.

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [December 3, 2020, 11:16am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/7 "2020-12-03T11:16:16Z")

</div>

> [@cemerick](#):
>
> I wonder if this library is something you wanted to build and share regardless, or if you had unsuccessfully looked for something like it previously? Despite good work in the community, discovering appropriate libraries can still be a bit of a challenge sometimes compared to fuller ecosystems.

The library organically grew mostly from my preference and experience of writing recursive descent parsers. Thus the name `reparse`.

My main motivation was “I like writing recursive descent parsers, how can I make the process of writing them productive and efficient”. The main pain point I initially wanted to address was to somehow abstract/encapsulate the parser state operations, e.g. get next char, is it eof, create lexer/parser buffer and so on. Such that if I wanted to implement a parser for one of the HTTP RFCs, I wouldn’t have to worry about parser state management every time I start work on a new parser.

It was doable and easy enough that I went ahead and did it. v0.0.1(not released) was just that. I used that in a few of my parsers and that worked quite well. From then onward it started taking shape of its own.

As an aside, v1.0.0 was using `result` type underneath as the central data type. However, I became quite disillusioned with the development experience of it so I removed it in v2.0.0 and used the venerable `exception` type.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![cemerick](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cemerick/32/1383_2.png) [@cemerick](https://discuss.ocaml.org/u/cemerick)\
**Post date:** [December 3, 2020, 4:24pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/8 "2020-12-03T16:24:34Z")

</div>

Exceptions vs. results in a library isn’t a massive hurdle, though I personally tend to catch and wrap exceptions as close to their sources as possible (and use exceptions in my own code mostly only for non-local jumps/returns). I _think_ that is mostly orthodoxy these days, though of course tastes vary.

Thanks very much for the background in general!

---

<div class="post-metadata">

**Author:** ![BikalGurung](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bikalgurung/32/5105_2.png) [@BikalGurung](https://discuss.ocaml.org/u/BikalGurung)\
**Post date:** [December 3, 2020, 5:38pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/9 "2020-12-03T17:38:36Z")

</div>

@rixed My initial - first draft - thoughts on exceptions vs result. [https://lemaetech.co.uk/articles/exceptions.html](https://lemaetech.co.uk/articles/exceptions.html)

---

<div class="post-metadata">

**Author:** ![rixed](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rixed/32/56_2.png) [@rixed](https://discuss.ocaml.org/u/rixed)\
**Post date:** [December 4, 2020, 6:32pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/10 "2020-12-04T18:32:32Z")

</div>

Thank you for having written this down. I came to the same conclusion for similar reasons, plus I really much prefer when the code is not splattered with error passing code (esp. when dealing with several libraries that use different conventions, as you noted).  
To me OCaml syntax is lean and light with exceptions but using monadic error handling lower the signal to noise ratio of the code significantly.  
If only we had a way to know statically which exceptions can escape any functions that would be the best of both worlds!

---

<div class="post-metadata">

**Author:** ![orbitz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/orbitz/32/110_2.png) [@orbitz](https://discuss.ocaml.org/u/orbitz)\
**Post date:** [December 7, 2020, 6:27am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/11 "2020-12-07T06:27:36Z")

</div>

Whoops, just found [https://lemaetech.co.uk/articles/exceptions.html](https://lemaetech.co.uk/articles/exceptions.html) ignore the below question

> [@BikalGurung](#):
>
> As an aside, v1.0.0 was using `result` type underneath as the central data type. However, I became quite disillusioned with the development experience of it so I removed it in v2.0.0 and used the venerable `exception` type.

Do you have any more details on this? I have been using `result` to `exceptions` for years and find it mostly-superior to exceptions and am curious what your experience was.

---

<div class="post-metadata">

**Author:** ![cemerick](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cemerick/32/1383_2.png) [@cemerick](https://discuss.ocaml.org/u/cemerick)\
**Post date:** [December 7, 2020, 7:40pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/12 "2020-12-07T19:40:21Z")

</div>

Thank you very much for your writeup! It ended up spurring me on to some further reading and conclusions that I formed into a separate post here:

> [@Exception vs Result](https://discuss.ocaml.org/t/exception-vs-result/6931):
>
> Last week, @BikalGurung blogged [On Effectiveness of Exceptions in OCaml](https://lemaetech.co.uk/articles/exceptions.html), in part as a follow-up to [his announcement of his parser combinator library](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868) [reparse](https://github.com/lemaetech/reparse/), which eschews Result-based error handling in favor of exceptions. I’ve long preferred using Result (and its equivalents in other languages), and my experience so far with OCaml is that that preference is shared by many in the community and by authors of key libraries, but I was happy to consider a new counterpoint. Doing so prompted me to …

---

<div class="post-metadata">

**Author:** ![jhw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jhw/32/1639_2.png) [@jhw](https://discuss.ocaml.org/u/jhw)\
**Post date:** [December 16, 2020, 10:27pm UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/13 "2020-12-16T22:27:07Z")

</div>

For what it’s worth, I remember making a similar choice to use the `exn` type for signaling errors when I was designing the [Orsetto](https://bitbucket.org/jhw/orsetto) recursive descent parser library. Mostly for the same reasons as you, but also because it facilitated composition of error recovery.

For example, Orsetto makes this function available to parsers:

```auto
    (** The error check scanner. Use [ck p] to create a new scanner that either
        produces either [Ok v] if [p] produces [v] or [Error x] if scanning the
        input with [p] raises an exception [x].
    *)
    val ck: 'r t -> ('r, exn) result t

```

p.s. I was aware of Angstrom when it was introduced. The origins of Orsetto preceded it. I’ve been supporting Orsetto for a very very long time. I am an old person.

---

<div class="post-metadata">

**Author:** ![jhw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jhw/32/1639_2.png) [@jhw](https://discuss.ocaml.org/u/jhw)\
**Post date:** [December 24, 2020, 12:15am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/14 "2020-12-24T00:15:33Z")

</div>

Also, I have a hunch that [JSON Test Suite](https://github.com/nst/JSONTestSuite) won’t like that example JSON parser very much. (Don’t feel bad: it hates everyone.)

---

<div class="post-metadata">

**Author:** ![jhw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jhw/32/1639_2.png) [@jhw](https://discuss.ocaml.org/u/jhw)\
**Post date:** [December 29, 2020, 7:18am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/15 "2020-12-29T07:18:04Z")

</div>

> [@jhw](#):
>
> I’ve been supporting [Orsetto](https://bitbucket.org/jhw/orsetto) for a very very long time. I am an old person.

I just finished updating all the copyright notices for 2020, and I’m somewhat knocked on my heels by the fact that some of these files are now old enough to be eligible for the military draft. And when I started messing around with OCaml, the compiler group had already end-of-lifed three previous major versions of the tool chain.

All this is to say— I’m taking this moment to reflect and appreciate the maturity of the OCaml language ecosystem.

---

<div class="post-metadata">

**Author:** ![xavierleroy](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xavierleroy](https://discuss.ocaml.org/u/xavierleroy)\
**Post date:** [December 29, 2020, 11:07am UTC](https://discuss.ocaml.org/t/ann-reparse-2-0-0/6868/16 "2020-12-29T11:07:48Z")

</div>

> [@jhw](#):
>
> All this is to say— I’m taking this moment to reflect and appreciate the maturity of the OCaml language ecosystem.

On a related note, see [Roberto Di Cosmo’s experience](https://hal.archives-ouvertes.fr/hal-02885664) with resurrecting OCaml code from 1998. Finding the sources was difficult, but the OCaml 1.07 sources compiled fine with OCaml 4.05, 20 years later.
