[wg-camlp4] My uses of syntax extension

Alain Frisch alain at frisch.fr
Tue Jan 29 13:37:37 GMT 2013


On 01/29/2013 02:17 PM, Leo White wrote:
> However, quotations should also be used in for extensions that are, as
> Gabriel put it, "mostly valid OCaml code". In these cases
> "anti-quotations" actually make up the majority of the text, and forcing
> an unnecessary heavyweight syntax for them will make these quotations
> very unwieldy.
>
> For example (a quotation for Haskell's arrow notation):
>
> <:proc < x ->           y <- f -< x + 1;
>            g -< 2 * y;
>            t <- h -< x * (x + y);
>            return -< t + y >>

I don't like this use of quotations for "mostly valid OCaml code": you 
loose all support from your editor, who has no way to recognize valid 
fragments of OCaml code inside the quotation.  For those case, I'd 
rather use a special marker (an attribute or something else) to identify 
a syntactic scope under which some existing constructions are re-used 
with a different meaning.  As long as the special marker is visible 
enough, I think it is fine to do so.  For instance, js_of_ocaml could 
support code like:

   (@js) (o.property)
   (@js) (o # method foobar)


I find quotations very well suited to embed fragments of existing 
foreign languages (XML, shell) while keeping their own syntax, including 
lexical conventions.  But in those cases, anti-quotations are often 
quite trivial (simple identifiers, field projection, simple function calls).


Alain


More information about the wg-camlp4 mailing list