[wg-camlp4] Against the use of syntactically-valid OCaml code for syntax extension purposes

Gabriel Scherer gabriel.scherer at gmail.com
Tue Jan 29 18:53:34 GMT 2013


I was going to suggest a related idea, having two syntaxes for "should
be tool-handled as valid OCaml code inside" and "should be
tool-handled as strings".

I'm not sure the idea of having "postfix" and "prefix" annotations
makes sense for all grammar rules (and mixing them with a modality of
"external or ocaml-syntax" feels like conflating separate concerns).
I'd rather consider where annotation may happen for grammar rules
individually. For example, in the case of "let p = e1 in e2", I'm
quite sure we may want to annotate either the whole expression or
specifically the declaration, and while I see how prefix and postfix
both make sense for the whole expression, I'm not sure they would both
make sense to annotate the binding, and considering only those cases
could lead them to being dropped.

Still in this case 'let p = e1 in e2', how should we distinguish:
- an annotation on the expressions 'e1' and 'e2'
- an annotation on the pattern 'p' (possibly seen as an expressions)
- an annotation on the binding itself
- an annotation on the expression as a whole?

In the case of embeddings of external syntaxes, it seems to be enough
to be able to embed into the expression and pattern syntactic classes
only (and not bindings in this example). I think annotations are
fairly different beasts.

On Tue, Jan 29, 2013 at 7:16 PM, Leo White <lpw25 at cam.ac.uk> wrote:
>> I propose to start discussing the addition of attributes to most syntactic
>> categories (expressions, type expressions, patterns, type declarations,
>> module expressions, structure/signature items, etc).  I suggest to adopt
>> "expressions" as the (default) nature of attribute's content, because the
>> syntax for expressions is quite flexible.  We need some syntax to attach
>> such an attribute to various syntactic categories.  It might be a good idea
>> to support both prefix and postfix attributes.  Personally I don't care too
>> much about the choice of syntax, and I'm very bad at picking good syntax.
>> Good proposal are welcome!
>
>
> How about allowing {: foo }, {% foo }, {@ foo },
> <: foo < bar >>, <% foo < bar >>  and <@ foo < bar >> ?
>
> The idea is that "{" means it is a valid OCaml expression as opposed to "<"
> which means it is an unlexed string.
>
> ":" means that it is an expression/pattern/type on its own and the
> type-checker should raise an error if it still exists after all
> preprocessing is done.
>
> "%" means it is a postfix attribute that can safely be ignored by the
> type-checker.
>
> "@" means it is a prefix attribute that can safely be ignored by the type
> checker.
>
> This seems fairly systematic and covers many possible use cases.
>


More information about the wg-camlp4 mailing list