[wg-camlp4] A new branch to experiment with extension points

Gabriel Scherer gabriel.scherer at gmail.com
Mon Mar 4 13:52:26 GMT 2013


Could Alain or Leo summarize what is the design space of safe
annotation grammars, lexing/parsing wise?

Some remarks on the current situation:

1. After thinking about it more, I regret the use of the (: foo)
syntax for two different reasons. For once, all delimiters in the
OCaml syntax so far are symmetric ([, {, (, but also [< and {<), and
I'm not sure there is a reason to break this here, so I'd rather have
(: foo :) (I asked the same question for my sequence-comprehension
camlp4 extension that started using [? foo ], then swichted to [? foo
?] -- with a lexer modification to handle those as two-char tokens) .
Another problematic aspect is that we already have ( exp : ty ) in the
OCaml grammar, and I'm not too happy with something that rather
closely looks like (: ty ). Finally, I'm not sure that it's wise to
eat up both (: and [: for related purposes; there are not a lot of
convenient delimiters (pretty much only (, [ and { ) and we will have
people suggesting new syntaxes for a lot of years to come. Could the
two syntaxes share a single delimiter prefix, for example [: and [:: ?

2. I'm unsure about generalization of the "with" syntax to other
syntactic cases. In expression context, "with" is very much associated
to pattern matching, and in particular there is syntactic contention
around a potential "let try ... = ... with ... in" construct. Using
"with" in local module open introduces avenue for confusion. The
with-syntax has the important advantage of internalizing an existing
practice in type-conv, but I'm not sure it scales so well to other
syntactic constructs. What is the current rationale for when to use
with, and when to use with (besides "when the grammar does not
conflict"?).

3. I think we really need a prefix syntax. If we where to use this
annotation syntax for compiler pragmas (locally enabling/disabling
some warning, for example), users would really want to be able to
write, say,

  begin [: pragma(non_exhaustive_match) :]
    ...
  end


On Mon, Mar 4, 2013 at 2:00 PM, Alain Frisch <alain.frisch at lexifi.com> wrote:
> On 03/04/2013 11:51 AM, Leo White wrote:
>>>
>>> Opinion on these changes?   I think it's rather important to agree on
>>> where attributes can be put exactly.
>>>
>>
>> That all seems reasonable to me.
>
>
> I've committed a version where attributes are mostly parsed as in your
> patch.
>
> Currently supported:
>
> - Attributes  .... [: lid expr ]
>   where .... can be:
>
>     a module expression
>     an expression
>     a type expression
>
> - Extension (: lid expr )
>   in position of a:
>
>    a module expression
>    an expression
>    a type expression
>
> - Attributes .... with lid1(expr1),..,lidn(exprn)
>   where .... can be:
>
>    a single type declaration
>    an open or include structure item (more to come)
>
>
> -- Alain
>
> _______________________________________________
> wg-camlp4 mailing list
> wg-camlp4 at lists.ocaml.org
> http://lists.ocaml.org/listinfo/wg-camlp4


More information about the wg-camlp4 mailing list