caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <alain@frisch.fr>
To: Benjamin Canou <benjamin.canou@gmail.com>, caml-list@inria.fr
Subject: Re: [Caml-list] proposal for finding, loading and composing ppx preprocessors
Date: Tue, 15 Jul 2014 17:56:34 +0200	[thread overview]
Message-ID: <53C54F32.6000201@frisch.fr> (raw)
In-Reply-To: <53C533CA.208@gmail.com>

On 07/15/2014 03:59 PM, Benjamin Canou wrote:
> My belief is that there is room for a less ambitious, plug-in based
> (statically or dynamically linked) annotation mechanism, on top of PPX.
> For instance, if we consider the current use of camlp4, we can assume
> that most ppxs will probably just define some annotation on some
> specific kind of AST node in order to rewrite them and / or insert
> auxiliary code, without carrying so much state. Having a common
> mechanism for registering such common simple tasks and assigning to
> names to them could be useful, without breaking the model.

The registration mechanism exists:  a ppx processor is supposed to call 
Ast_mapper.register.  By default, this runs directly the main program to 
support for ppx protocol for this single processor, but you can very 
well override the behavior of Ast_mapper.register by calling 
Ast_mapper.register_function first.

You can look at https://github.com/alainfrisch/ppx_drivers for an 
experiment of creating such a driver.

But this notion of registration is quite independent on how multiple 
processors interact.  I'm yet to be convinced that a composition mode 
more fine-grained that function composition is worth the extra mental 
overhead.  It would also be necessary to decide between top-down and 
bottom-up rewriting, none of them being the best pick for all 
processors.  Typically, a macro expander would want other processors to 
apply to the result of macro expansions (i.e. top-down rewriting style), 
while a type-conv-like processor might prefer a bottom-up rewriting (so 
that the macro expander can run first on type declarations before it 
takes control).

Concerning the notion of state in ppx processors, I've written the 
following ppx processors:

  - sedlex (a lexer generator): it needs to remember about all lexer 
definitions in the current unit to be able to generate some global 
function definitions (shared by various lexers)  (for instance, we don't 
want to generate definitions used only by code that would be excluded by 
a conditional compilation processor)

  - ppx_metaquot: some extension nodes with very short names %e, %t, %p 
are recognized only in the context of an enclosing extension node such 
as %expr ( 
https://github.com/alainfrisch/ppx_tools/blob/master/ppx_metaquot.ml )

I expect most other ppx processors to be slightly more complex than 
purely local transformations, which makes it even more difficult to 
reason on local composition (and "purely local" term rewriting systems 
are already hard to reason about their composition).

> Well, one of the use cases of extension nodes is to integrate external
> notations into literals such as [%json{| ... |}]. I believe IDEs could
> still use a little help to know how to format these, instead of showing
> plain OCaml strings.

Indeed, although I think this is going to be a rather rare use of 
extension points / quoted strings.


-- Alain

      reply	other threads:[~2014-07-15 15:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-11 13:31 Benjamin Canou
2014-07-11 14:21 ` Daniel Bünzli
2014-07-11 14:36   ` Peter Zotov
2014-07-11 14:49     ` Daniel Bünzli
2014-07-11 14:55       ` Peter Zotov
2014-07-11 14:52     ` Mark Shinwell
2014-07-11 15:27     ` Anil Madhavapeddy
2014-07-11 15:35       ` Mark Shinwell
2014-07-11 14:55   ` Benjamin Canou
2014-07-11 15:23     ` Daniel Bünzli
2014-07-11 16:00       ` Benjamin Canou
2014-07-11 16:13 ` Alain Frisch
2014-07-15 13:59   ` Benjamin Canou
2014-07-15 15:56     ` Alain Frisch [this message]

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=53C54F32.6000201@frisch.fr \
    --to=alain@frisch.fr \
    --cc=benjamin.canou@gmail.com \
    --cc=caml-list@inria.fr \
    /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).