caml-list - the Caml user's mailing list
 help / Atom feed
* [Caml-list] camlp4 & OCaml 4.08
@ 2019-06-27 13:45 Richard W.M. Jones
  2019-06-27 17:28 ` Ian Zimmerman
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Richard W.M. Jones @ 2019-06-27 13:45 UTC (permalink / raw)
  To: caml-list


I know camlp4 is dead and all that, but we've got some software which
still uses it.  I will probably port it to camlp5 when I have the
time, but has anyone got the patch to make camlp4 work with 4.08?

Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-27 13:45 [Caml-list] camlp4 & OCaml 4.08 Richard W.M. Jones
@ 2019-06-27 17:28 ` Ian Zimmerman
  2019-06-27 20:00   ` Richard W.M. Jones
  2019-06-27 18:09 ` Jürgen Hötzel
  2019-06-29  9:06 ` Anil Madhavapeddy
  2 siblings, 1 reply; 22+ messages in thread
From: Ian Zimmerman @ 2019-06-27 17:28 UTC (permalink / raw)
  To: caml-list

On 2019-06-27 14:45, Richard W.M. Jones wrote:

> 
> I know camlp4 is dead and all that, but we've got some software which
> still uses it.  I will probably port it to camlp5 when I have the
> time, but has anyone got the patch to make camlp4 work with 4.08?

Isn't it the case that camlp5 doesn't work with 4.08 either?

-- 
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-27 13:45 [Caml-list] camlp4 & OCaml 4.08 Richard W.M. Jones
  2019-06-27 17:28 ` Ian Zimmerman
@ 2019-06-27 18:09 ` Jürgen Hötzel
  2019-06-29  9:06 ` Anil Madhavapeddy
  2 siblings, 0 replies; 22+ messages in thread
From: Jürgen Hötzel @ 2019-06-27 18:09 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 485 bytes --]

Same here:

still a lot of Arch Linux packages depend (make) on camlp4:
https://www.archlinux.org/packages/community/x86_64/camlp4/

so I'm stuck in the OCaml 4.08 rebuild.

Regards,


On Thu, Jun 27, 2019 at 3:45 PM Richard W.M. Jones <rich@annexia.org> wrote:

>
> I know camlp4 is dead and all that, but we've got some software which
> still uses it.  I will probably port it to camlp5 when I have the
> time, but has anyone got the patch to make camlp4 work with 4.08?
>
> Rich.
>

[-- Attachment #2: Type: text/html, Size: 1136 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-27 17:28 ` Ian Zimmerman
@ 2019-06-27 20:00   ` Richard W.M. Jones
  0 siblings, 0 replies; 22+ messages in thread
From: Richard W.M. Jones @ 2019-06-27 20:00 UTC (permalink / raw)
  To: Ian Zimmerman; +Cc: caml-list

On Thu, Jun 27, 2019 at 10:28:54AM -0700, Ian Zimmerman wrote:
> On 2019-06-27 14:45, Richard W.M. Jones wrote:
> 
> > 
> > I know camlp4 is dead and all that, but we've got some software which
> > still uses it.  I will probably port it to camlp5 when I have the
> > time, but has anyone got the patch to make camlp4 work with 4.08?
> 
> Isn't it the case that camlp5 doesn't work with 4.08 either?

A patch for 4.08 was pushed to the camlp5 repo a few hours ago.
I've used it successfully.

Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-27 13:45 [Caml-list] camlp4 & OCaml 4.08 Richard W.M. Jones
  2019-06-27 17:28 ` Ian Zimmerman
  2019-06-27 18:09 ` Jürgen Hötzel
@ 2019-06-29  9:06 ` Anil Madhavapeddy
  2019-06-29  9:43   ` Richard W.M. Jones
  2019-06-29 15:15   ` Daniil Baturin
  2 siblings, 2 replies; 22+ messages in thread
From: Anil Madhavapeddy @ 2019-06-29  9:06 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: caml-list

On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org> wrote:
> 
> 
> I know camlp4 is dead and all that, but we've got some software which
> still uses it.  I will probably port it to camlp5 when I have the
> time, but has anyone got the patch to make camlp4 work with 4.08?


To fork the thread slightly,  how big are the camlp4 dependencies remaining
in your codebase, and is there anything we can do to help migrate?

It's pretty exhausting trying to keep camlp4 maintained with a skeleton
crew, and there appears to be a stubborn tail of packages which aren't
migrating despite it having been quite a few years since the deprecation.

Having said that, patches for 4.08 support for camlp4 are also welcome
if anyone wants to step up to help maintain it. It's only deprecated from
the perspective of being bundled with the core compiler distribution,
and is now deprecated due to lack of programmer-will to keep it going.

regards,
Anil

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-29  9:06 ` Anil Madhavapeddy
@ 2019-06-29  9:43   ` Richard W.M. Jones
       [not found]     ` <12C0FD24-2DCD-4128-B020-84416F228E87@metastack.com>
  2019-07-02 14:30     ` Louis Gesbert
  2019-06-29 15:15   ` Daniil Baturin
  1 sibling, 2 replies; 22+ messages in thread
From: Richard W.M. Jones @ 2019-06-29  9:43 UTC (permalink / raw)
  To: Anil Madhavapeddy; +Cc: caml-list, sylvain

On Sat, Jun 29, 2019 at 10:06:15AM +0100, Anil Madhavapeddy wrote:
> On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org> wrote:
> > 
> > 
> > I know camlp4 is dead and all that, but we've got some software which
> > still uses it.  I will probably port it to camlp5 when I have the
> > time, but has anyone got the patch to make camlp4 work with 4.08?
> 
> 
> To fork the thread slightly,  how big are the camlp4 dependencies remaining
> in your codebase, and is there anything we can do to help migrate?

The dependencies that I care about run through ocaml-gettext.  Gettext
is a specific method to make code internationalized and by its nature
it involves deep changes throughout our codebase, so porting away from
ocaml-gettext isn't an option any time soon.  However porting
ocaml-gettext to use something else might be.

ocaml-gettext has a tool which runs over the OCaml source code and
extracts the magic translatable strings, and it's my understanding
that this is the only reason it uses camlp4.  AIUI this cannot be done
using ppx's (maybe I'm wrong about that?) but could be done using
camlp5.  In fact it was me who did the original port of ocaml-gettext
from old camlp4 (ie. camlp5) to camlp4(!)

(see libgettext-ocaml/pr_gettext.ml in the OCaml sources)

> It's pretty exhausting trying to keep camlp4 maintained with a skeleton
> crew, and there appears to be a stubborn tail of packages which aren't
> migrating despite it having been quite a few years since the deprecation.

I agree, however also changing working code is always a pain and
there's never a good time.

Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
       [not found]     ` <12C0FD24-2DCD-4128-B020-84416F228E87@metastack.com>
@ 2019-06-29 10:52       ` Richard W.M. Jones
  2019-06-29 17:49         ` Sylvain Le Gall
  2019-06-30  8:55         ` David Allsopp
  0 siblings, 2 replies; 22+ messages in thread
From: Richard W.M. Jones @ 2019-06-29 10:52 UTC (permalink / raw)
  To: David Allsopp; +Cc: Anil Madhavapeddy, caml-list, sylvain

On Sat, Jun 29, 2019 at 10:17:02AM +0000, David Allsopp wrote:
> > On 29 Jun 2019, at 10:44, Richard W.M. Jones <rich@annexia.org> wrote:
> > 
> >> On Sat, Jun 29, 2019 at 10:06:15AM +0100, Anil Madhavapeddy wrote:
> >>> On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org> wrote:
> >>> 
> >>> 
> >>> I know camlp4 is dead and all that, but we've got some software which
> >>> still uses it.  I will probably port it to camlp5 when I have the
> >>> time, but has anyone got the patch to make camlp4 work with 4.08?
> >> 
> >> 
> >> To fork the thread slightly,  how big are the camlp4 dependencies remaining
> >> in your codebase, and is there anything we can do to help migrate?
> > 
> > The dependencies that I care about run through ocaml-gettext.  Gettext
> > is a specific method to make code internationalized and by its nature
> > it involves deep changes throughout our codebase, so porting away from
> > ocaml-gettext isn't an option any time soon.  However porting
> > ocaml-gettext to use something else might be.
> > 
> > ocaml-gettext has a tool which runs over the OCaml source code and
> > extracts the magic translatable strings, and it's my understanding
> > that this is the only reason it uses camlp4.  AIUI this cannot be done
> > using ppx's (maybe I'm wrong about that?) but could be done using
> > camlp5.  In fact it was me who did the original port of ocaml-gettext
> > from old camlp4 (ie. camlp5) to camlp4(!)
> 
> It’s not instantly clear to my (non-expert) eyes why this can’t be done with PPX. If I read the camlp4 script correctly, it doesn’t introduce any new syntax, it just matches on particular function calls and rewrites them?

Actually I believe it simply extracts the string parameters into a
separate file (from where they get translated).  However it's a
separate tool, it doesn't run as part of ordinary compilation.

Rich.

-- 
Richard Jones

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-29  9:06 ` Anil Madhavapeddy
  2019-06-29  9:43   ` Richard W.M. Jones
@ 2019-06-29 15:15   ` Daniil Baturin
       [not found]     ` <5CE377AD-CB06-4261-BD26-A2A697253F02@uca.fr>
  1 sibling, 1 reply; 22+ messages in thread
From: Daniil Baturin @ 2019-06-29 15:15 UTC (permalink / raw)
  To: caml-list

On 6/29/19 4:06 PM, Anil Madhavapeddy wrote:
> On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org> wrote:
>>
>> I know camlp4 is dead and all that, but we've got some software which
>> still uses it.  I will probably port it to camlp5 when I have the
>> time, but has anyone got the patch to make camlp4 work with 4.08?
>
> To fork the thread slightly,  how big are the camlp4 dependencies remaining
> in your codebase, and is there anything we can do to help migrate?
>
> It's pretty exhausting trying to keep camlp4 maintained with a skeleton
> crew, and there appears to be a stubborn tail of packages which aren't
> migrating despite it having been quite a few years since the deprecation.
>
> Having said that, patches for 4.08 support for camlp4 are also welcome
> if anyone wants to step up to help maintain it. It's only deprecated from
> the perspective of being bundled with the core compiler distribution,
> and is now deprecated due to lack of programmer-will to keep it going.
>
> regards,
> Anil

My feeling is that many of those packages still use camlp4 because their
maintainers haven't got time to update them,
rather than due to unending love for camlp4.
Some packages may not even actually use camlp4 at all, it's just their
build setup that requires it.

Perhaps we should make some coordinated effort to help them.
I've just sent a pull request to the ocamldot maintainer that enables
the graphviz files parsing and printing modules
to build and work with 4.08. The GTK parts have their own issues.
Next I'm going to look into LASCAR/RFSM (packages that interest me first ;).

If anyone wants to join the review and patch making process, let me know.
Maybe make a forum thread or an issue in some repo with a dependent
package checklist we can strike through.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-29 10:52       ` Richard W.M. Jones
@ 2019-06-29 17:49         ` Sylvain Le Gall
  2019-07-18 14:23           ` Richard W.M. Jones
  2019-06-30  8:55         ` David Allsopp
  1 sibling, 1 reply; 22+ messages in thread
From: Sylvain Le Gall @ 2019-06-29 17:49 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: David Allsopp, Anil Madhavapeddy, caml-list

AFAIR, it only extracts "s_ STRING". You just need something that will
pattern match a function name ("s_") and a string.

I don't know enough PPX to decide if it is easy to port or not. I'll
gladly integrate anything that will replace campl5/campl4 by PPX.

Feel free to send me PR on this.
Regards
Sylvain

Le sam. 29 juin 2019 à 12:52, Richard W.M. Jones <rich@annexia.org> a écrit :
>
> On Sat, Jun 29, 2019 at 10:17:02AM +0000, David Allsopp wrote:
> > > On 29 Jun 2019, at 10:44, Richard W.M. Jones <rich@annexia.org> wrote:
> > >
> > >> On Sat, Jun 29, 2019 at 10:06:15AM +0100, Anil Madhavapeddy wrote:
> > >>> On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org> wrote:
> > >>>
> > >>>
> > >>> I know camlp4 is dead and all that, but we've got some software which
> > >>> still uses it.  I will probably port it to camlp5 when I have the
> > >>> time, but has anyone got the patch to make camlp4 work with 4.08?
> > >>
> > >>
> > >> To fork the thread slightly,  how big are the camlp4 dependencies remaining
> > >> in your codebase, and is there anything we can do to help migrate?
> > >
> > > The dependencies that I care about run through ocaml-gettext.  Gettext
> > > is a specific method to make code internationalized and by its nature
> > > it involves deep changes throughout our codebase, so porting away from
> > > ocaml-gettext isn't an option any time soon.  However porting
> > > ocaml-gettext to use something else might be.
> > >
> > > ocaml-gettext has a tool which runs over the OCaml source code and
> > > extracts the magic translatable strings, and it's my understanding
> > > that this is the only reason it uses camlp4.  AIUI this cannot be done
> > > using ppx's (maybe I'm wrong about that?) but could be done using
> > > camlp5.  In fact it was me who did the original port of ocaml-gettext
> > > from old camlp4 (ie. camlp5) to camlp4(!)
> >
> > It’s not instantly clear to my (non-expert) eyes why this can’t be done with PPX. If I read the camlp4 script correctly, it doesn’t introduce any new syntax, it just matches on particular function calls and rewrites them?
>
> Actually I believe it simply extracts the string parameters into a
> separate file (from where they get translated).  However it's a
> separate tool, it doesn't run as part of ordinary compilation.
>
> Rich.
>
> --
> Richard Jones

^ permalink raw reply	[flat|nested] 22+ messages in thread

* RE: [Caml-list] camlp4 & OCaml 4.08
  2019-06-29 10:52       ` Richard W.M. Jones
  2019-06-29 17:49         ` Sylvain Le Gall
@ 2019-06-30  8:55         ` David Allsopp
  2019-07-01 13:40           ` Jeremie Dimino
  1 sibling, 1 reply; 22+ messages in thread
From: David Allsopp @ 2019-06-30  8:55 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: Anil Madhavapeddy, caml-list, sylvain

Richard W.M. Jones wrote:
> On Sat, Jun 29, 2019 at 10:17:02AM +0000, David Allsopp wrote:
> > > On 29 Jun 2019, at 10:44, Richard W.M. Jones <rich@annexia.org> wrote:
> > >
> > >> On Sat, Jun 29, 2019 at 10:06:15AM +0100, Anil Madhavapeddy wrote:
> > >>> On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org>
> > >>> wrote:
> > >>>
> > >>>
> > >>> I know camlp4 is dead and all that, but we've got some software
> > >>> which still uses it.  I will probably port it to camlp5 when I
> > >>> have the time, but has anyone got the patch to make camlp4 work with
> > >>> 4.08?
> > >>
> > >>
> > >> To fork the thread slightly,  how big are the camlp4 dependencies
> > >> remaining in your codebase, and is there anything we can do to help
> > >> migrate?
> > >
> > > The dependencies that I care about run through ocaml-gettext.
> > > Gettext is a specific method to make code internationalized and by
> > > its nature it involves deep changes throughout our codebase, so
> > > porting away from ocaml-gettext isn't an option any time soon.
> > > However porting ocaml-gettext to use something else might be.
> > >
> > > ocaml-gettext has a tool which runs over the OCaml source code and
> > > extracts the magic translatable strings, and it's my understanding
> > > that this is the only reason it uses camlp4.  AIUI this cannot be
> > > done using ppx's (maybe I'm wrong about that?) but could be done
> > > using camlp5.  In fact it was me who did the original port of
> > > ocaml-gettext from old camlp4 (ie. camlp5) to camlp4(!)
> >
> > It’s not instantly clear to my (non-expert) eyes why this can’t be done
> with PPX. If I read the camlp4 script correctly, it doesn’t introduce any
> new syntax, it just matches on particular function calls and rewrites
> them?
> 
> Actually I believe it simply extracts the string parameters into a
> separate file (from where they get translated).  However it's a separate
> tool, it doesn't run as part of ordinary compilation.

As I say, I've not done it, but walking an AST to pattern match those things sounds eminently doable. Similarly, I've not done it, but producing a driver program is one of the raison d'etre of ppxlib (or ppx-driver, as was).


David


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-30  8:55         ` David Allsopp
@ 2019-07-01 13:40           ` Jeremie Dimino
  0 siblings, 0 replies; 22+ messages in thread
From: Jeremie Dimino @ 2019-07-01 13:40 UTC (permalink / raw)
  To: David Allsopp
  Cc: Richard W.M. Jones, Anil Madhavapeddy, caml users, Sylvain Le Gall

FTR, I had considered modernising camlp4 to make its maintenance
easier, however due to its complexity it is a lot of work. Right now,
keeping camlp4 alive and up to date is indeed painful and complicated.
Additionally, I don't think it's a good idea to keep such projects
that are basically abandoned on life support forever as it is giving
the false impression that they are still actively maintained.


On Sun, Jun 30, 2019 at 9:56 AM David Allsopp <dra-news@metastack.com> wrote:
>
> Richard W.M. Jones wrote:
> > On Sat, Jun 29, 2019 at 10:17:02AM +0000, David Allsopp wrote:
> > > > On 29 Jun 2019, at 10:44, Richard W.M. Jones <rich@annexia.org> wrote:
> > > >
> > > >> On Sat, Jun 29, 2019 at 10:06:15AM +0100, Anil Madhavapeddy wrote:
> > > >>> On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org>
> > > >>> wrote:
> > > >>>
> > > >>>
> > > >>> I know camlp4 is dead and all that, but we've got some software
> > > >>> which still uses it.  I will probably port it to camlp5 when I
> > > >>> have the time, but has anyone got the patch to make camlp4 work with
> > > >>> 4.08?
> > > >>
> > > >>
> > > >> To fork the thread slightly,  how big are the camlp4 dependencies
> > > >> remaining in your codebase, and is there anything we can do to help
> > > >> migrate?
> > > >
> > > > The dependencies that I care about run through ocaml-gettext.
> > > > Gettext is a specific method to make code internationalized and by
> > > > its nature it involves deep changes throughout our codebase, so
> > > > porting away from ocaml-gettext isn't an option any time soon.
> > > > However porting ocaml-gettext to use something else might be.
> > > >
> > > > ocaml-gettext has a tool which runs over the OCaml source code and
> > > > extracts the magic translatable strings, and it's my understanding
> > > > that this is the only reason it uses camlp4.  AIUI this cannot be
> > > > done using ppx's (maybe I'm wrong about that?) but could be done
> > > > using camlp5.  In fact it was me who did the original port of
> > > > ocaml-gettext from old camlp4 (ie. camlp5) to camlp4(!)
> > >
> > > It’s not instantly clear to my (non-expert) eyes why this can’t be done
> > with PPX. If I read the camlp4 script correctly, it doesn’t introduce any
> > new syntax, it just matches on particular function calls and rewrites
> > them?
> >
> > Actually I believe it simply extracts the string parameters into a
> > separate file (from where they get translated).  However it's a separate
> > tool, it doesn't run as part of ordinary compilation.
>
> As I say, I've not done it, but walking an AST to pattern match those things sounds eminently doable. Similarly, I've not done it, but producing a driver program is one of the raison d'etre of ppxlib (or ppx-driver, as was).
>
>
> David
>


-- 
Jeremie

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-29  9:43   ` Richard W.M. Jones
       [not found]     ` <12C0FD24-2DCD-4128-B020-84416F228E87@metastack.com>
@ 2019-07-02 14:30     ` Louis Gesbert
  1 sibling, 0 replies; 22+ messages in thread
From: Louis Gesbert @ 2019-07-02 14:30 UTC (permalink / raw)
  To: caml-list, Richard W.M. Jones; +Cc: Anil Madhavapeddy, sylvain

[-- Attachment #1: Type: text/plain, Size: 3070 bytes --]

For what it's worth, Learn-OCaml [1] uses a rather straightfoward way to handle translations through PPX, based on the gettext format.

It's a quick hack and the build-system around it could use some cleanup, though, which is the reason why it wasn't released as a library: please consider it a proof of concept that PPX can be used for gettext.

- Translatable strings are introduced through [%i "Blah" ] (or [%if "Blah"] for format-strings; advanced uses like changing format parameters order are not supported)

- The build extracts these to a separate file at build-time, based on an environment variable `DUMP_POT` [2]. Probably the most dirty part here, and it requires a clean build, but it works...

- Then the standard GNU tools can be used to manage the translations [3]

- There is a tiny library at runtime that allows choosing the locale; located strings are rewritten to arrays with a lookup based on it (but changing that to something more elaborate like using external resource files should be pretty straightforward) [4].

Louis Gesbert -- OCamlPro

[1] https://github.com/ocaml-sf/learn-ocaml/
[2] https://github.com/ocaml-sf/learn-ocaml/blob/master/src/utils/ppx_ocplib_i18n.ml
[3] https://github.com/ocaml-sf/learn-ocaml/blob/master/Makefile#L33
[4] https://github.com/ocaml-sf/learn-ocaml/blob/master/src/utils/ocplib_i18n.mli

> - Richard W.M. Jones, 29/06/2019 10:43 -
> On Sat, Jun 29, 2019 at 10:06:15AM +0100, Anil Madhavapeddy wrote:
> > On 27 Jun 2019, at 14:45, Richard W.M. Jones <rich@annexia.org> wrote:
> > > 
> > > 
> > > I know camlp4 is dead and all that, but we've got some software which
> > > still uses it.  I will probably port it to camlp5 when I have the
> > > time, but has anyone got the patch to make camlp4 work with 4.08?
> > 
> > 
> > To fork the thread slightly,  how big are the camlp4 dependencies remaining
> > in your codebase, and is there anything we can do to help migrate?
> 
> The dependencies that I care about run through ocaml-gettext.  Gettext
> is a specific method to make code internationalized and by its nature
> it involves deep changes throughout our codebase, so porting away from
> ocaml-gettext isn't an option any time soon.  However porting
> ocaml-gettext to use something else might be.
> 
> ocaml-gettext has a tool which runs over the OCaml source code and
> extracts the magic translatable strings, and it's my understanding
> that this is the only reason it uses camlp4.  AIUI this cannot be done
> using ppx's (maybe I'm wrong about that?) but could be done using
> camlp5.  In fact it was me who did the original port of ocaml-gettext
> from old camlp4 (ie. camlp5) to camlp4(!)
> 
> (see libgettext-ocaml/pr_gettext.ml in the OCaml sources)
> 
> > It's pretty exhausting trying to keep camlp4 maintained with a skeleton
> > crew, and there appears to be a stubborn tail of packages which aren't
> > migrating despite it having been quite a few years since the deprecation.
> 
> I agree, however also changing working code is always a pain and
> there's never a good time.
> 
> Rich.
> 

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] Lascar/RFSM & Camlp4 (was camlp4 & OCaml 4.08)
       [not found]       ` <393603fa-0efa-5714-82da-ba4bc3e869b8@baturin.org>
@ 2019-07-05  9:55         ` Jocelyn Sérot
  2019-07-24 15:10         ` [Caml-list] Camlp4-free implementation of stream parsers " Jocelyn Sérot
  1 sibling, 0 replies; 22+ messages in thread
From: Jocelyn Sérot @ 2019-07-05  9:55 UTC (permalink / raw)
  To: Daniil Baturin; +Cc: caml users

Hi Danill - and sorry for the late answer.

Yes, Lascar only use camlp4 for stream expressions (using the Genlex to parse small expressions).
I’ve checked, and i cant find any reference to camlp4 in the latest version of Rfsm; i can’t remember why i put it the package dependency list (because it itself depends on Lascar ?).
You’re much welcome to work on path. 

Jocelyn

Le 2 juil. 2019 à 11:25, Daniil Baturin <daniil@baturin.org> a écrit :

> Hi Jocelyn,
> Camlp5 is still sort of maintained, but I don't think it's going to be
> developed beyond compatibility updates.
> For syntax extensions, everyone is switching to PPX.
> 
> From a quick look, it seems like the only bit of camlp4 you use is
> stream expressions.
> This is one of the things PPX can't do (on purpose, since it doesn't
> allow _arbitrary_ extensions),
> but I don't think just using streams directly is going to make code much
> longer.
> 
> Or I missed some other camlp4 bits?
> 
> I'm ready to work on a patch if you are open to it.
> 
> On 7/2/19 1:44 PM, Jocelyn Sérot wrote:
>> Le 29 juin 2019 à 17:15, Daniil Baturin <daniil@baturin.org> a écrit :
>> 
>>> Perhaps we should make some coordinated effort to help them.
>>> I've just sent a pull request to the ocamldot maintainer that enables
>>> the graphviz files parsing and printing modules
>>> to build and work with 4.08. The GTK parts have their own issues.
>>> Next I'm going to look into LASCAR/RFSM (packages that interest me first ;).
>>> 
>> Hi Daniil,
>> 
>> I’ve been been thinking of removing the dependency of Lascar and RFSM on camlp4 for a while.
>> Is switching to CamlP5 a good alternative ? 
>> 
>> Jocelyn
>> 
>> 
> 
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-06-29 17:49         ` Sylvain Le Gall
@ 2019-07-18 14:23           ` Richard W.M. Jones
  2019-07-23  8:12             ` Richard W.M. Jones
  0 siblings, 1 reply; 22+ messages in thread
From: Richard W.M. Jones @ 2019-07-18 14:23 UTC (permalink / raw)
  To: Sylvain Le Gall; +Cc: David Allsopp, Anil Madhavapeddy, caml-list


Needs a bit of extra help, but I think I've done most of the
hard work to get it to work with ppx:

https://github.com/gildor478/ocaml-gettext/pull/4

I ran some test extractions on real code and the generated
messages.po files looked reasonable.

Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-07-18 14:23           ` Richard W.M. Jones
@ 2019-07-23  8:12             ` Richard W.M. Jones
  2019-07-23 16:33               ` Sylvain Le Gall
  0 siblings, 1 reply; 22+ messages in thread
From: Richard W.M. Jones @ 2019-07-23  8:12 UTC (permalink / raw)
  To: Sylvain Le Gall; +Cc: David Allsopp, Anil Madhavapeddy, caml-list


Hey Sylvain, there's another one in case you didn't see it:

https://github.com/gildor478/ocaml-gettext/pull/5

Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-07-23  8:12             ` Richard W.M. Jones
@ 2019-07-23 16:33               ` Sylvain Le Gall
  2019-07-23 16:37                 ` Richard W.M. Jones
  0 siblings, 1 reply; 22+ messages in thread
From: Sylvain Le Gall @ 2019-07-23 16:33 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: David Allsopp, Anil Madhavapeddy, caml-list

Merged.

Sorry, I work on a different project right now. Once I'll be done with
this other project, I'll do a release of ocaml-gettext.

Le mar. 23 juil. 2019 à 01:12, Richard W.M. Jones <rich@annexia.org> a écrit :
>
>
> Hey Sylvain, there's another one in case you didn't see it:
>
> https://github.com/gildor478/ocaml-gettext/pull/5
>
> Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] camlp4 & OCaml 4.08
  2019-07-23 16:33               ` Sylvain Le Gall
@ 2019-07-23 16:37                 ` Richard W.M. Jones
  0 siblings, 0 replies; 22+ messages in thread
From: Richard W.M. Jones @ 2019-07-23 16:37 UTC (permalink / raw)
  To: Sylvain Le Gall; +Cc: David Allsopp, Anil Madhavapeddy, caml-list

On Tue, Jul 23, 2019 at 09:33:46AM -0700, Sylvain Le Gall wrote:
> Merged.
> 
> Sorry, I work on a different project right now. Once I'll be done with
> this other project, I'll do a release of ocaml-gettext.

No problem, thanks for looking into it.

Rich.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Caml-list] Camlp4-free implementation of stream parsers (was camlp4 & OCaml 4.08)
       [not found]       ` <393603fa-0efa-5714-82da-ba4bc3e869b8@baturin.org>
  2019-07-05  9:55         ` [Caml-list] Lascar/RFSM & Camlp4 (was camlp4 & OCaml 4.08) Jocelyn Sérot
@ 2019-07-24 15:10         ` " Jocelyn Sérot
  2019-07-24 15:31           ` Daniil Baturin
  1 sibling, 1 reply; 22+ messages in thread
From: Jocelyn Sérot @ 2019-07-24 15:10 UTC (permalink / raw)
  To: Daniil Baturin; +Cc: caml users

Hi Daniil (and everyone interested by the subject),

Did you have a closer look at this ? 

I’m still hesitating between these three approaches for replacing the implementation of the small arithm expression parser used in Lascar [1] :

i. rewrite it using the basic fns provided by the Stream library (pro: no additionnal dependency, cons: not so trivial..)

ii. replace camlp4 by camlp5 (pro: straightforward, cons: long term maintainability of camlp5 (?)) 

iii. rewrite it using ocamlex/menhir and embed it in the main code (pro: « standard » soon; cons: a bit heavy)

Jocelyn

[1] https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml, lines 70–112

Le 2 juil. 2019 à 11:25, Daniil Baturin <daniil@baturin.org> a écrit :

> Hi Jocelyn,
> Camlp5 is still sort of maintained, but I don't think it's going to be
> developed beyond compatibility updates.
> For syntax extensions, everyone is switching to PPX.
> 
> From a quick look, it seems like the only bit of camlp4 you use is
> stream expressions.
> This is one of the things PPX can't do (on purpose, since it doesn't
> allow _arbitrary_ extensions),
> but I don't think just using streams directly is going to make code much
> longer.
> 
> Or I missed some other camlp4 bits?
> 
> I'm ready to work on a patch if you are open to it.
> 
> On 7/2/19 1:44 PM, Jocelyn Sérot wrote:
>> Le 29 juin 2019 à 17:15, Daniil Baturin <daniil@baturin.org> a écrit :
>> 
>>> Perhaps we should make some coordinated effort to help them.
>>> I've just sent a pull request to the ocamldot maintainer that enables
>>> the graphviz files parsing and printing modules
>>> to build and work with 4.08. The GTK parts have their own issues.
>>> Next I'm going to look into LASCAR/RFSM (packages that interest me first ;).
>>> 
>> Hi Daniil,
>> 
>> I’ve been been thinking of removing the dependency of Lascar and RFSM on camlp4 for a while.
>> Is switching to CamlP5 a good alternative ? 
>> 
>> Jocelyn
>> 
>> 
> 
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] Camlp4-free implementation of stream parsers (was camlp4 & OCaml 4.08)
  2019-07-24 15:10         ` [Caml-list] Camlp4-free implementation of stream parsers " Jocelyn Sérot
@ 2019-07-24 15:31           ` Daniil Baturin
  0 siblings, 0 replies; 22+ messages in thread
From: Daniil Baturin @ 2019-07-24 15:31 UTC (permalink / raw)
  To: Jocelyn Sérot; +Cc: caml users

Hi Jocelyn,

I've completed the first version of my project, so now I can start
looking into this again!

There's a third option: parser combinators like angstrom.
My experience with Menhir is very positive though. After initial
struggle, I came to like its new incremental API and declarative error
reporting.

Here's my parser for an extended BNF:
Menhir grammar:
https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.mly
Parser driver that feeds it tokens:
https://github.com/dmbaturin/bnfgen/blob/master/src/parse_bnf.ml
Error messages:
https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.messages
Error message module build:
https://github.com/dmbaturin/bnfgen/blob/master/src/dune#L6-L8

On 7/24/19 10:10 PM, Jocelyn Sérot wrote:
> Hi Daniil (and everyone interested by the subject),
>
> Did you have a closer look at this ? 
>
> I’m still hesitating between these three approaches for replacing the implementation of the small arithm expression parser used in Lascar [1] :
>
> i. rewrite it using the basic fns provided by the Stream library (pro: no additionnal dependency, cons: not so trivial..)
>
> ii. replace camlp4 by camlp5 (pro: straightforward, cons: long term maintainability of camlp5 (?)) 
>
> iii. rewrite it using ocamlex/menhir and embed it in the main code (pro: « standard » soon; cons: a bit heavy)
>
> Jocelyn
>
> [1] https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml, lines 70–112
>
> Le 2 juil. 2019 à 11:25, Daniil Baturin <daniil@baturin.org> a écrit :
>
>> Hi Jocelyn,
>> Camlp5 is still sort of maintained, but I don't think it's going to be
>> developed beyond compatibility updates.
>> For syntax extensions, everyone is switching to PPX.
>>
>> From a quick look, it seems like the only bit of camlp4 you use is
>> stream expressions.
>> This is one of the things PPX can't do (on purpose, since it doesn't
>> allow _arbitrary_ extensions),
>> but I don't think just using streams directly is going to make code much
>> longer.
>>
>> Or I missed some other camlp4 bits?
>>
>> I'm ready to work on a patch if you are open to it.
>>
>> On 7/2/19 1:44 PM, Jocelyn Sérot wrote:
>>> Le 29 juin 2019 à 17:15, Daniil Baturin <daniil@baturin.org> a écrit :
>>>
>>>> Perhaps we should make some coordinated effort to help them.
>>>> I've just sent a pull request to the ocamldot maintainer that enables
>>>> the graphviz files parsing and printing modules
>>>> to build and work with 4.08. The GTK parts have their own issues.
>>>> Next I'm going to look into LASCAR/RFSM (packages that interest me first ;).
>>>>
>>> Hi Daniil,
>>>
>>> I’ve been been thinking of removing the dependency of Lascar and RFSM on camlp4 for a while.
>>> Is switching to CamlP5 a good alternative ? 
>>>
>>> Jocelyn
>>>
>>>
>>



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] Camlp4-free implementation of stream parsers (was camlp4 & OCaml 4.08)
       [not found] <C4399DA5-3383-4A7E-9546-0021083D6EF3@uca.fr>
@ 2019-07-25 10:27 ` Jocelyn Sérot
  2019-07-25 11:42   ` Gabriel Scherer
  0 siblings, 1 reply; 22+ messages in thread
From: Jocelyn Sérot @ 2019-07-25 10:27 UTC (permalink / raw)
  To: caml users

HI Daniil,

Thanks for the example. It clearly shows how to embed a Menhir-specified parser into an existing program.

I still think, however that using Menhir for parsing arithmetic expressions is a bit overkill.

I’m having a look at Angstrom (and all the other parser combinator libs cited on the corresp. page).
It seems simpler. 

Jocelyn

Le 24 juil. 2019 à 17:31, Daniil Baturin <daniil@baturin.org> a écrit :

> Hi Jocelyn,
> 
> I've completed the first version of my project, so now I can start
> looking into this again!
> 
> There's a third option: parser combinators like angstrom.
> My experience with Menhir is very positive though. After initial
> struggle, I came to like its new incremental API and declarative error
> reporting.
> 
> Here's my parser for an extended BNF:
> Menhir grammar:
> https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.mly
> Parser driver that feeds it tokens:
> https://github.com/dmbaturin/bnfgen/blob/master/src/parse_bnf.ml
> Error messages:
> https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.messages
> Error message module build:
> https://github.com/dmbaturin/bnfgen/blob/master/src/dune#L6-L8
> 
> On 7/24/19 10:10 PM, Jocelyn Sérot wrote:
>> Hi Daniil (and everyone interested by the subject),
>> 
>> Did you have a closer look at this ? 
>> 
>> I’m still hesitating between these three approaches for replacing the implementation of the small arithm expression parser used in Lascar [1] :
>> 
>> i. rewrite it using the basic fns provided by the Stream library (pro: no additionnal dependency, cons: not so trivial..)
>> 
>> ii. replace camlp4 by camlp5 (pro: straightforward, cons: long term maintainability of camlp5 (?)) 
>> 
>> iii. rewrite it using ocamlex/menhir and embed it in the main code (pro: « standard » soon; cons: a bit heavy)
>> 
>> Jocelyn
>> 
>> [1] https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml, lines 70–112
>> 
>> Le 2 juil. 2019 à 11:25, Daniil Baturin <daniil@baturin.org> a écrit :
>> 
>>> Hi Jocelyn,
>>> Camlp5 is still sort of maintained, but I don't think it's going to be
>>> developed beyond compatibility updates.
>>> For syntax extensions, everyone is switching to PPX.
>>> 
>>> From a quick look, it seems like the only bit of camlp4 you use is
>>> stream expressions.
>>> This is one of the things PPX can't do (on purpose, since it doesn't
>>> allow _arbitrary_ extensions),
>>> but I don't think just using streams directly is going to make code much
>>> longer.
>>> 
>>> Or I missed some other camlp4 bits?
>>> 
>>> I'm ready to work on a patch if you are open to it.
>>> 
>>> On 7/2/19 1:44 PM, Jocelyn Sérot wrote:
>>>> Le 29 juin 2019 à 17:15, Daniil Baturin <daniil@baturin.org> a écrit :
>>>> 
>>>>> Perhaps we should make some coordinated effort to help them.
>>>>> I've just sent a pull request to the ocamldot maintainer that enables
>>>>> the graphviz files parsing and printing modules
>>>>> to build and work with 4.08. The GTK parts have their own issues.
>>>>> Next I'm going to look into LASCAR/RFSM (packages that interest me first ;).
>>>>> 
>>>> Hi Daniil,
>>>> 
>>>> I’ve been been thinking of removing the dependency of Lascar and RFSM on camlp4 for a while.
>>>> Is switching to CamlP5 a good alternative ? 
>>>> 
>>>> Jocelyn
>>>> 
>>>> 
>>> 
> 
> 



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] Camlp4-free implementation of stream parsers (was camlp4 & OCaml 4.08)
  2019-07-25 10:27 ` Jocelyn Sérot
@ 2019-07-25 11:42   ` Gabriel Scherer
  2019-07-25 15:20     ` Jocelyn Sérot
  0 siblings, 1 reply; 22+ messages in thread
From: Gabriel Scherer @ 2019-07-25 11:42 UTC (permalink / raw)
  To: Jocelyn Sérot; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 5053 bytes --]

Hi,

The parser from
https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml seems
fairly trivial, have you considered just rewriting it to use the functions
of the Stream primitives directly?

For example, roughly (I have not tried to type-check or test the code),

    let rec aux = parser
    | [< 'Int n when n<0; t=aux >] -> [< 'Kwd "-"; 'Int (-n); t >]
    | [< 'h; t=aux >] -> [< 'h; t >]
    | [< >] -> [< >] in

would become

    let aux s =
      let next = ref [] in
      Stream.from @@ fun _ ->
        match !next with
        | tok::toks -> next := toks; Some tok
        | [] -> match Stream.next with
                | exception Stream.Failure -> None
                | Int n when n < 0 ->
                  next := [Int (-n)];
                  Some (Kwd "-")
                | tok -> Some tok

and

    let rec p_exp0  = parser
    | [< 'Int n >] -> EConst n
    | [< 'Ident i >] -> EVar i
    | [< 'Kwd "("; e=p_exp ; 'Kwd ")" >] -> e

becomes

    let rec p_exp0 s = match Stream.next s with
    | Int n -> EConst n
    | Ident i -> EVar i
    | Kwd "(" ->
      let e = p_exp s in
      match Stream.peek s with
      | Some (Kwd ")") -> Stream.junk s; e
      | _ -> raise Stream.Failure

This is not exactly exciting code to write, but it's not a lot of work
either for such a simple grammar.

On Thu, Jul 25, 2019 at 12:28 PM Jocelyn Sérot <jocelyn.serot@uca.fr> wrote:

> HI Daniil,
>
> Thanks for the example. It clearly shows how to embed a Menhir-specified
> parser into an existing program.
>
> I still think, however that using Menhir for parsing arithmetic
> expressions is a bit overkill.
>
> I’m having a look at Angstrom (and all the other parser combinator libs
> cited on the corresp. page).
> It seems simpler.
>
> Jocelyn
>
> Le 24 juil. 2019 à 17:31, Daniil Baturin <daniil@baturin.org> a écrit :
>
> > Hi Jocelyn,
> >
> > I've completed the first version of my project, so now I can start
> > looking into this again!
> >
> > There's a third option: parser combinators like angstrom.
> > My experience with Menhir is very positive though. After initial
> > struggle, I came to like its new incremental API and declarative error
> > reporting.
> >
> > Here's my parser for an extended BNF:
> > Menhir grammar:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.mly
> > Parser driver that feeds it tokens:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/parse_bnf.ml
> > Error messages:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.messages
> > Error message module build:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/dune#L6-L8
> >
> > On 7/24/19 10:10 PM, Jocelyn Sérot wrote:
> >> Hi Daniil (and everyone interested by the subject),
> >>
> >> Did you have a closer look at this ?
> >>
> >> I’m still hesitating between these three approaches for replacing the
> implementation of the small arithm expression parser used in Lascar [1] :
> >>
> >> i. rewrite it using the basic fns provided by the Stream library (pro:
> no additionnal dependency, cons: not so trivial..)
> >>
> >> ii. replace camlp4 by camlp5 (pro: straightforward, cons: long term
> maintainability of camlp5 (?))
> >>
> >> iii. rewrite it using ocamlex/menhir and embed it in the main code
> (pro: « standard » soon; cons: a bit heavy)
> >>
> >> Jocelyn
> >>
> >> [1] https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml,
> lines 70–112
> >>
> >> Le 2 juil. 2019 à 11:25, Daniil Baturin <daniil@baturin.org> a écrit :
> >>
> >>> Hi Jocelyn,
> >>> Camlp5 is still sort of maintained, but I don't think it's going to be
> >>> developed beyond compatibility updates.
> >>> For syntax extensions, everyone is switching to PPX.
> >>>
> >>> From a quick look, it seems like the only bit of camlp4 you use is
> >>> stream expressions.
> >>> This is one of the things PPX can't do (on purpose, since it doesn't
> >>> allow _arbitrary_ extensions),
> >>> but I don't think just using streams directly is going to make code
> much
> >>> longer.
> >>>
> >>> Or I missed some other camlp4 bits?
> >>>
> >>> I'm ready to work on a patch if you are open to it.
> >>>
> >>> On 7/2/19 1:44 PM, Jocelyn Sérot wrote:
> >>>> Le 29 juin 2019 à 17:15, Daniil Baturin <daniil@baturin.org> a écrit
> :
> >>>>
> >>>>> Perhaps we should make some coordinated effort to help them.
> >>>>> I've just sent a pull request to the ocamldot maintainer that enables
> >>>>> the graphviz files parsing and printing modules
> >>>>> to build and work with 4.08. The GTK parts have their own issues.
> >>>>> Next I'm going to look into LASCAR/RFSM (packages that interest me
> first ;).
> >>>>>
> >>>> Hi Daniil,
> >>>>
> >>>> I’ve been been thinking of removing the dependency of Lascar and RFSM
> on camlp4 for a while.
> >>>> Is switching to CamlP5 a good alternative ?
> >>>>
> >>>> Jocelyn
> >>>>
> >>>>
> >>>
> >
> >
>
>
>

[-- Attachment #2: Type: text/html, Size: 8298 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Caml-list] Camlp4-free implementation of stream parsers (was camlp4 & OCaml 4.08)
  2019-07-25 11:42   ` Gabriel Scherer
@ 2019-07-25 15:20     ` Jocelyn Sérot
  0 siblings, 0 replies; 22+ messages in thread
From: Jocelyn Sérot @ 2019-07-25 15:20 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 7990 bytes --]

Thanks for the suggestion, Gabriel.

It is indeed less tiresome that i had imagined.

I attach the corresponding full code (with original camlp4 formulation in comment).
Handling of the minus operator is here handled before parsing; this is not a problem since such a parser is supposed to be called on very small strings in practice.

Jocelyn

ps : i’m still wondering whether some library and/or ppx-based  generic (afap) implementation of Camlp4 stream parsers is possible..

8<—— Stream-based parser for simple arithmetic expressions (with non-negative integers)

type ident = string 

type value = int 

type t = 
  EConst of value              (** Constants *)   
| EVar of ident                (** Input, output or local variable *)
| EBinop of string * t * t     (** Binary operation *)

let keywords = ["+"; "-"; "*"; "/"; "("; ")"]

let mk_binary_minus s = s |> String.split_on_char '-' |> String.concat " - "
                      
let lexer s = s |> mk_binary_minus |> Stream.of_string |> Genlex.make_lexer keywords 

open Genlex

(* let rec p_exp0  = parser
 *                 | [< 'Int n >] -> EConst n
 *                 | [< 'Ident i >] -> EVar i
 *                 | [< 'Kwd "("; e=p_exp ; 'Kwd ")" >] -> e *)

let rec p_exp0 s =
  match Stream.next s with
    | Int n -> EConst n
    | Ident i -> EVar i
    | Kwd "(" ->
       let e = p_exp s in
       begin match Stream.peek s with
       | Some (Kwd ")") -> Stream.junk s; e
       | _ -> raise Stream.Failure
       end
    | _ -> raise Stream.Failure

(* and p_exp1  = parser
 *             | [< e1=p_exp0 ; rest >] -> p_exp2  e1 rest *)

and p_exp1 s =
  let e1 = p_exp0 s in
  p_exp2 e1 s
  
(* and p_exp2  e1 = parser
 *                | [< 'Kwd "*"; e2=p_exp1  >] -> EBinop("*", e1, e2)
 *                | [< 'Kwd "/"; e2=p_exp1  >] -> EBinop("/", e1, e2)
 *                | [< >] -> e1 *)

and p_exp2 e1 s =
  match Stream.peek s with
  | Some (Kwd "*") -> Stream.junk s; let e2 = p_exp1 s in EBinop("*", e1, e2)
  | Some (Kwd "/") -> Stream.junk s; let e2 = p_exp1 s in EBinop("/", e1, e2)
  | _ -> e1
  
(* and p_exp  = parser
 *            | [< e1=p_exp1 ; rest >] -> p_exp3  e1 rest *)

and p_exp s =
  let e1 = p_exp1 s in p_exp3 e1 s
                     
(* and p_exp3  e1 = parser
 *                | [< 'Kwd "+"; e2=p_exp  >] -> EBinop("+", e1, e2)
 *                | [< 'Kwd "-"; e2=p_exp  >] -> EBinop("-", e1, e2)
 *                | [< >] -> e1 *)

and p_exp3 e1 s =
  match Stream.peek s with
  | Some (Kwd "+") -> Stream.junk s; let e2 = p_exp s in EBinop("+", e1, e2)
  | Some (Kwd "-") -> Stream.junk s; let e2 = p_exp s in EBinop("-", e1, e2)
  | _ -> e1

let parse s = s |> lexer |> p_exp


Le 25 juil. 2019 à 13:42, Gabriel Scherer <gabriel.scherer@gmail.com> a écrit :

> Hi,
> 
> The parser from https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml seems fairly trivial, have you considered just rewriting it to use the functions of the Stream primitives directly?
> 
> For example, roughly (I have not tried to type-check or test the code),
> 
>     let rec aux = parser
>     | [< 'Int n when n<0; t=aux >] -> [< 'Kwd "-"; 'Int (-n); t >]
>     | [< 'h; t=aux >] -> [< 'h; t >]
>     | [< >] -> [< >] in
> 
> would become
> 
>     let aux s =
>       let next = ref [] in
>       Stream.from @@ fun _ ->
>         match !next with
>         | tok::toks -> next := toks; Some tok
>         | [] -> match Stream.next with
>                 | exception Stream.Failure -> None
>                 | Int n when n < 0 ->
>                   next := [Int (-n)];
>                   Some (Kwd "-")
>                 | tok -> Some tok
>  
> and
> 
>     let rec p_exp0  = parser
>     | [< 'Int n >] -> EConst n
>     | [< 'Ident i >] -> EVar i
>     | [< 'Kwd "("; e=p_exp ; 'Kwd ")" >] -> e        
> 
> becomes
> 
>     let rec p_exp0 s = match Stream.next s with
>     | Int n -> EConst n
>     | Ident i -> EVar i
>     | Kwd "(" ->
>       let e = p_exp s in
>       match Stream.peek s with
>       | Some (Kwd ")") -> Stream.junk s; e
>       | _ -> raise Stream.Failure
> 
> This is not exactly exciting code to write, but it's not a lot of work either for such a simple grammar.
> 
> On Thu, Jul 25, 2019 at 12:28 PM Jocelyn Sérot <jocelyn.serot@uca.fr> wrote:
> HI Daniil,
> 
> Thanks for the example. It clearly shows how to embed a Menhir-specified parser into an existing program.
> 
> I still think, however that using Menhir for parsing arithmetic expressions is a bit overkill.
> 
> I’m having a look at Angstrom (and all the other parser combinator libs cited on the corresp. page).
> It seems simpler. 
> 
> Jocelyn
> 
> Le 24 juil. 2019 à 17:31, Daniil Baturin <daniil@baturin.org> a écrit :
> 
> > Hi Jocelyn,
> > 
> > I've completed the first version of my project, so now I can start
> > looking into this again!
> > 
> > There's a third option: parser combinators like angstrom.
> > My experience with Menhir is very positive though. After initial
> > struggle, I came to like its new incremental API and declarative error
> > reporting.
> > 
> > Here's my parser for an extended BNF:
> > Menhir grammar:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.mly
> > Parser driver that feeds it tokens:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/parse_bnf.ml
> > Error messages:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/bnf_parser.messages
> > Error message module build:
> > https://github.com/dmbaturin/bnfgen/blob/master/src/dune#L6-L8
> > 
> > On 7/24/19 10:10 PM, Jocelyn Sérot wrote:
> >> Hi Daniil (and everyone interested by the subject),
> >> 
> >> Did you have a closer look at this ? 
> >> 
> >> I’m still hesitating between these three approaches for replacing the implementation of the small arithm expression parser used in Lascar [1] :
> >> 
> >> i. rewrite it using the basic fns provided by the Stream library (pro: no additionnal dependency, cons: not so trivial..)
> >> 
> >> ii. replace camlp4 by camlp5 (pro: straightforward, cons: long term maintainability of camlp5 (?)) 
> >> 
> >> iii. rewrite it using ocamlex/menhir and embed it in the main code (pro: « standard » soon; cons: a bit heavy)
> >> 
> >> Jocelyn
> >> 
> >> [1] https://github.com/jserot/lascar/blob/master/src/lib/fsm_expr.ml, lines 70–112
> >> 
> >> Le 2 juil. 2019 à 11:25, Daniil Baturin <daniil@baturin.org> a écrit :
> >> 
> >>> Hi Jocelyn,
> >>> Camlp5 is still sort of maintained, but I don't think it's going to be
> >>> developed beyond compatibility updates.
> >>> For syntax extensions, everyone is switching to PPX.
> >>> 
> >>> From a quick look, it seems like the only bit of camlp4 you use is
> >>> stream expressions.
> >>> This is one of the things PPX can't do (on purpose, since it doesn't
> >>> allow _arbitrary_ extensions),
> >>> but I don't think just using streams directly is going to make code much
> >>> longer.
> >>> 
> >>> Or I missed some other camlp4 bits?
> >>> 
> >>> I'm ready to work on a patch if you are open to it.
> >>> 
> >>> On 7/2/19 1:44 PM, Jocelyn Sérot wrote:
> >>>> Le 29 juin 2019 à 17:15, Daniil Baturin <daniil@baturin.org> a écrit :
> >>>> 
> >>>>> Perhaps we should make some coordinated effort to help them.
> >>>>> I've just sent a pull request to the ocamldot maintainer that enables
> >>>>> the graphviz files parsing and printing modules
> >>>>> to build and work with 4.08. The GTK parts have their own issues.
> >>>>> Next I'm going to look into LASCAR/RFSM (packages that interest me first ;).
> >>>>> 
> >>>> Hi Daniil,
> >>>> 
> >>>> I’ve been been thinking of removing the dependency of Lascar and RFSM on camlp4 for a while.
> >>>> Is switching to CamlP5 a good alternative ? 
> >>>> 
> >>>> Jocelyn
> >>>> 
> >>>> 
> >>> 
> > 
> > 
> 
> 


[-- Attachment #2: Type: text/html, Size: 17622 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, back to index

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-27 13:45 [Caml-list] camlp4 & OCaml 4.08 Richard W.M. Jones
2019-06-27 17:28 ` Ian Zimmerman
2019-06-27 20:00   ` Richard W.M. Jones
2019-06-27 18:09 ` Jürgen Hötzel
2019-06-29  9:06 ` Anil Madhavapeddy
2019-06-29  9:43   ` Richard W.M. Jones
     [not found]     ` <12C0FD24-2DCD-4128-B020-84416F228E87@metastack.com>
2019-06-29 10:52       ` Richard W.M. Jones
2019-06-29 17:49         ` Sylvain Le Gall
2019-07-18 14:23           ` Richard W.M. Jones
2019-07-23  8:12             ` Richard W.M. Jones
2019-07-23 16:33               ` Sylvain Le Gall
2019-07-23 16:37                 ` Richard W.M. Jones
2019-06-30  8:55         ` David Allsopp
2019-07-01 13:40           ` Jeremie Dimino
2019-07-02 14:30     ` Louis Gesbert
2019-06-29 15:15   ` Daniil Baturin
     [not found]     ` <5CE377AD-CB06-4261-BD26-A2A697253F02@uca.fr>
     [not found]       ` <393603fa-0efa-5714-82da-ba4bc3e869b8@baturin.org>
2019-07-05  9:55         ` [Caml-list] Lascar/RFSM & Camlp4 (was camlp4 & OCaml 4.08) Jocelyn Sérot
2019-07-24 15:10         ` [Caml-list] Camlp4-free implementation of stream parsers " Jocelyn Sérot
2019-07-24 15:31           ` Daniil Baturin
     [not found] <C4399DA5-3383-4A7E-9546-0021083D6EF3@uca.fr>
2019-07-25 10:27 ` Jocelyn Sérot
2019-07-25 11:42   ` Gabriel Scherer
2019-07-25 15:20     ` Jocelyn Sérot

caml-list - the Caml user's mailing list

Archives are clonable:
	git clone --mirror http://inbox.vuxu.org/caml-list
	git clone --mirror https://inbox.ocaml.org/caml-list

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.caml-list


AGPL code for this site: git clone https://public-inbox.org/ public-inbox