[wg-camlp4] Meta Programming from the view of the implementaion

Alain Frisch alain at frisch.fr
Wed Jan 30 14:41:23 GMT 2013


On 01/30/2013 12:21 PM, Leo White wrote:
>>  - The closing delimiter is defined by the opening one, so you don't
>> need any escaping convention.  (Imagine you want to write HTML code
>> containing ">>".)
>
> As I suggested in an earlier post, it is simple to allow this for <: ... >.
>
>>  (@sedlex) match lexbuf with
>>   | {{ xml_letter+ }} -> ...
>>   | {{ "with" }} -> ...
>>   | ...
>
> I suppose that it is sometimes useful to have an unnamed quotation. For
> this I think that camlp4 has "<< ... >>", so we could just allow that.

The important point is not the fact that the quotation is unnamed, but 
that it's scope is restricted to the smallest fragment which requires a 
custom parser (left-hand side).  I'm fine if those regexps cannot be 
highlighted very cleverly.  But what is important is that the right-hand 
side, which are normal OCaml expressions, are understood as such by the 
editor.  This cannot be the case with Hongbo's proposal of having the 
whole think inside a quotation:

{:lex|
    xml_letter+ -> ...
  | "with" -> ...
|}


So in this example:

   (@sedlex) match lexbuf with
    | {{ xml_letter+ }} -> ...
    | {{ "with" }} -> ...
    | ...

the role of {{...}} is not to introduce something which will expand to 
an expression or a pattern, it's just a way to avoid lexical rules on 
OCaml string literals (so that we don't need to escape the ").  The 
important part is the (@sedlex) attribute, and I wouldn't be shocked to 
use a different syntax to indicate that it really changes the 
interpretation of the underlying expression (the whole match statement), 
as opposed to some piece of information added to that expression.  The 
syntax could be simply changing (@sedlex) to (:sedlex), or maybe to have 
it look more like a delimiter with a clear scope:

  (:sedlex
     match lexbuf with
     | {{ xml_letter+ }} -> ...
     | {{ "with" }} -> ...
     | ...
  )

but the content would still be parsed as an expression, unlike camlp4 
quotations.


>> As a side note, whatever syntax we choose for quotations / non-parsed
>> strings, we should avoid the one currently used by Camlp4, because for
>> some time, people will continue to use both Camlp4 and -ppx rewriters.
>
> I disagree with this. It is not at all difficult to tell camlp4 to pass
> through unrecognised quotations onto the main compiler (and so to the
> other preprocessors). It would then be simple for quotation extensions
> to seamlessly switch from -pp to -ppx.

Ok, why not.  I still believe that real uses of "quotations" should be 
really limited and that most interesting uses of -ppx would not need 
them (or be independent from them, i.e. they should allow regular string 
literals as well).


Alain


More information about the wg-camlp4 mailing list