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

Leo White lpw25 at cam.ac.uk
Wed Jan 30 15:11:47 GMT 2013


>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.
>

How about we broaden "quotations" (which to avoid confusion I'm going to 
start calling "templates") to allow the following two forms:

* <: lid expr >
* <: lid ?< unlexed-text >?>

(where ? can be any symbol or alpha-numberic character or empty)

The second form would essentially be syntactic sugar for <: lid {{ }} >. It 
is there for convenience and to preserve backward compatibility with 
camlp4.

Notice that they require an identifier. I think that this is a good thing 
because it helps prevent name clashes. It is also probably necessary for 
supporting <:foo < .. >> in the same construct.

Separate from this we also support "attributes" like (@ expr).

This should still allow you to use:

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

or even

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

if you prefer it.



More information about the wg-camlp4 mailing list