[wg-camlp4] My uses of syntax extension

Leo White lpw25 at cam.ac.uk
Tue Jan 29 13:17:19 GMT 2013


> From the implementation point-of-view, you have to know all the parsers 
>at parsing time, because you need the function to recognize their 
>antiquotations.

I don't think that this is the case. I think that with a bit of care you 
can provide a function like:

anti-expr: (char Stream.t -> bool) -> char Stream.t -> Parsetree.expression

where the first argument is a predicate that tests for the end of the 
anti-quotation.

This function could be used by an extension whether it is expanded before 
or during type-checking.

> From the accessibility point-of-view, having a convention for 
>quotations/anti-quotations is both simpler for users (they can 
>understand more of what is happening even if they don't know the syntax 
>extensions, because anti-quotations are always written in the same way)

This seems to assume that quotations are for a sub-language that is nothing 
like OCaml, and so anti-quotations should be clearly marked. 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 >>

is definitely preferable to:

<:proc < $x$ -> 
           y <- $f$ -< $x + 1$;
           $g$ -< $2 * y$;
           t <- $h$ -< $x * (x + y)$;
           $return$ -< $t + y$ >>



More information about the wg-camlp4 mailing list