caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas Ojeda Bar <no263@dpmms.cam.ac.uk>
To: Gerd Stolpmann <info@gerd-stolpmann.de>
Cc: Francois.Pottier@inria.fr, caml-list@inria.fr
Subject: Re: [Caml-list] New release of Menhir (20141215)
Date: Thu, 18 Dec 2014 11:19:55 -0300	[thread overview]
Message-ID: <CAPunWhD=DgnPRXJo60ppx_sGbGeVbzYSXDCqffk2dMKJ8K=Vdw@mail.gmail.com> (raw)
In-Reply-To: <1418906703.5445.5.camel@e130.lan.sumadev.de>

Hi Gerd,

I wrote an IMAP client library in pure OCaml
(https://github.com/nojb/ocaml-imap).  It can handle the full RFC 3501
grammar.  This library itself is not yet ready for prime-time, but I
spent quite a bit of time thinking about the question of parsing since
it is such a big part of the protocol.

While the incremental parsing in the new Menhir is great I do not
think it will help to parse IMAP because the token types of IMAP
grammar are highly context dependent.  By this I mean that there are
many overlapping token definitions that are valid in different parts
of the grammar.  While this could be hacked around (by changing the
lexer used in dummy non-terminals) the complexity of doing so quickly
gets out of hand.  In my view this almost requires using a scannerless
parser, which rules out ocamlyacc/menhir-type parsers.

A parser generator that could handle the IMAP grammar nicely is Dypgen
(which generates GLR parsers).  You can almost copy the IMAP grammar
verbatim from RFC 3501.  However it can not be made incremental.  This
means that you need to have all the input available before starting
the parse.  Since the amount of data is potentially very big, this
rules using Dypgen for anything else than toy applications.

In my library I use a monadic combinator parser
(https://github.com/nojb/ocaml-imap/blob/master/imap/imapParser.ml).
When programming monadically you are reifying the continuation at
every `bind` point so you get the incremental bit for free (I think
this goes by the fancy name of `iteratees` nowadays).  On the other
hand it suffers from poor time/space performance common to this type
of parser.  Also, while combinator parsers can handle arbitrary
backtracking (and you end up paying for this), IMAP itself requires
very little, so it would seem that the full flexibility of combinators
are not needed.

It seems that the "scannerless, incremental" space in parser
technology is not very developed (in OCaml; maybe other languages is
different ?).  One intriguing possibility that I am exploring (but
this is a much longer term project) is to use PEG parsers for this.
It would be easy to write an IMAP parser with PEG. The main problem is
that the usual implementation of PEG parsers uses memoization to keep
parsing time from blowing up exponentially on the length of input (
(in OCaml the Aurochs parser generator is of this type).  This
requires storage proportional to input length, which is a problem when
parsing large amounts of data.  But for grammars that don't need a lot
of backtracking (like IMAP) the memoization is not actually required,
so I think there is an interesting space to explore between all these
constraints.

In any case, I would love to hear about your experience if you do try
to parse IMAP using Menhir.

Best wishes,
Nicolas

On Thu, Dec 18, 2014 at 9:45 AM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> Thanks for this, it is great news. A couple of months ago I tried to
> develop a monadic parser for the IMAP protocol, which has a weird
> grammar and needs some strange interactions between lexing and parsing.
> Lacking a parser generator I started to write the parser manually, but
> it never made good progress. It looks like Menhir can now be used for
> this case, and I'll try it.
>
> Gerd
>
> Am Mittwoch, den 17.12.2014, 21:14 +0100 schrieb Francois Pottier:
>> Dear OCaml users,
>>
>> I have recently started making a series of changes in Menhir, inspired by
>> the work of Frédéric Bour on Merlin (a smart emacs-mode for OCaml, which
>> uses a modified version of Menhir). Thanks to Frédéric for his stimulating
>> ideas, and thanks to Gabriel Scherer for not letting me sleep until I
>> promised I would do something about them! :-)
>>
>> I have made a first release a couple days ago. The relevant chunk of the
>> CHANGES file is appended below. In summary, a new incremental API is
>> available; Menhir now requires ocaml 4.02; and a couple of obscure features
>> (--error-recovery and $previouserror) have been removed in the interest of
>> speed and simplicity.
>>
>> The incremental API means that you can take a snapshot of the parser's state,
>> essentially at no cost, at any time. It also means that the parser no longer
>> drives the lexer; you drive the lexer, and you provide tokens to the parser
>> when it requests them. This can be convenient if the lexer is in a monad (the
>> Lwt monad, for instance).
>>
>> More changes are planned. The type "env" exposed by the new incremental API is
>> currently opaque. We are planning to offer a range of functions that allow
>> inspecting and building values of type "env". This should allow the user to
>> implement new error handling and error recovery strategies outside of Menhir.
>>
>> The new release is available now as a .tar.gz archive:
>>
>>   http://gallium.inria.fr/~fpottier/menhir/menhir-20141215.tar.gz
>>
>> It is also available via opam ("opam install menhir").
>>
>> Cheers,
>>
>> --
>> François Pottier
>> Francois.Pottier@inria.fr
>> http://gallium.inria.fr/~fpottier/
>>
>> 2014/12/15:
>> New incremental API (in --table mode only), inspired by Frédéric Bour.
>>
>> 2014/12/11:
>> Menhir now reports an error if one of the start symbols produces
>> either the empty language or the singleton language {epsilon}.
>>
>> Although some people out there actually define a start symbol that recognizes
>> {epsilon} (and use it as a way of initializing or re-initializing some global
>> state), this is considered bad style. Furthermore, by ruling out this case, we
>> are able to simplify the table back-end a little bit.
>>
>> 2014/12/12:
>> A speed improvement in the code back-end.
>>
>> 2014/12/08:
>> Menhir now requires OCaml 4.02 (instead of 3.09).
>>
>> 2014/12/02:
>> Removed support for the $previouserror keyword.
>> Removed support for --error-recovery mode.
>>
>
> --
> ------------------------------------------------------------
> Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
> My OCaml site:          http://www.camlcity.org
> Contact details:        http://www.camlcity.org/contact.html
> Company homepage:       http://www.gerd-stolpmann.de
> ------------------------------------------------------------
>

  reply	other threads:[~2014-12-18 14:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-17 20:14 Francois Pottier
2014-12-18 12:45 ` Gerd Stolpmann
2014-12-18 14:19   ` Nicolas Ojeda Bar [this message]
2014-12-18 15:20     ` Daniel Bünzli
2014-12-18 15:34       ` Simon Cruanes
2014-12-18 16:02         ` Nicolas Ojeda Bar
2014-12-18 15:25     ` Gerd Stolpmann
2014-12-18 17:25       ` Francois Pottier
2014-12-22 11:13     ` oleg
2014-12-22 18:40 ` Dario Teixeira
2014-12-24 23:30   ` Francois Pottier
2014-12-26 11:13     ` Dario Teixeira
2014-12-26 11:31       ` Frédéric Bour
2014-12-26 12:16         ` Dario Teixeira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPunWhD=DgnPRXJo60ppx_sGbGeVbzYSXDCqffk2dMKJ8K=Vdw@mail.gmail.com' \
    --to=no263@dpmms.cam.ac.uk \
    --cc=Francois.Pottier@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=info@gerd-stolpmann.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).