paurkedal / ppx_regexp

Matching Regular Expressions with OCaml Patterns
GNU Lesser General Public License v3.0
56 stars 3 forks source link

Working with tyre #2

Closed Drup closed 6 years ago

Drup commented 6 years ago

I'm currently considering taking a second look at tyre, and that involves writing a ppx for it. ppx_regexp does, as far as I'm concerned, many things right and I agree with the goal to make it accessible. So I'm considering simply extending it. That involves two things:

  1. Modifying the typing rules to return _ list for groups under repetitions and `Left of _ | `Right of _ for groups under alternatives. See if the result is sufficiently usable, and maybe modify Tyre so that it is.
  2. Figuring out composition.

Now, I recently got a decent idea for 2: Reuse the syntax for recursion into named groups from PCRE2. (?&potato) would simply use the (typed) regular expression named potato. This would also allow to have more primitive datatypes, for example (?&int).

What do you think? Do you want to join forces? :)

paurkedal commented 6 years ago

Heads-up: I split up the opam packages moving some files in the process, so remember to pull before you start working on something.

It the solution for sharing the Regexp module involves copy, since dune does not have libtool-style convenience libraries. Let me know if you know a better alternative. If not I think this is a workable solution as longs as it's only one or a few modules.

Feel free to rewrite the ppx_tyre.descr. We'll also paste and expand on that in the README.

Drup commented 6 years ago

So, holidays were nice! :D

I made a new release of tyre which uses the new Seq type for repetitions, instead of Gen, so ppx_tyre can use that. I then added simple tests (I was a bit lazy, so I copied and tweaked yours). On the way, I improved the extraction for toplevel named captures (so that it behaves like ppx_regexp and directly bring the name in scope). I also found a bug in the new tyre release, which I couldn't fix before going in holidays. This is now done, tyre 0.4.1 is released, everything is ready!

paurkedal commented 6 years ago

Yes, had a few days in the mountains myself, but back within reach of electronic communication since this weekend. I'll take a last look now, maybe extend the tests a bit, before releasing v0.4.0.

paurkedal commented 6 years ago

I pushed a few commits earlier today and merged into master including CI, and improved test of the parser. Note also that I bumped the OCaml version constraint for ppx_tyre to 4.06 due to List.init.

I think we're ready too now. Will make the release tomorrow.

Drup commented 6 years ago

I extended the tyre part quite a lot with small examples.

paurkedal commented 6 years ago

I opened ocaml/opam-repository#12492.

Drup commented 6 years ago

Who posts the announcement everywhere ? :)

paurkedal commented 6 years ago

PR accepted already :-) Yes, we should announce this, at least in the forum. Would you like to do the honours, given the tyre support is the big news? Otherwise, any particular points or examples we should include? For ppx_regexp I would mention something to the effect of: "The ppx_regexp package will continue to be supported. This version fixes a bug related to the type of captures under alternatives, and now uses an internal regexp parser shared with ppx_tyre."

Drup commented 6 years ago

Sure! Will do tomorrow! I'll do a post on my blog and repost it everywhere :p

paurkedal commented 6 years ago

Thanks!