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

Alain Frisch alain.frisch at lexifi.com
Wed Mar 6 16:28:01 GMT 2013


On 03/06/2013 05:03 PM, Xavier Clerc wrote:
> Thanks for the clarification. However, I am now afraid about user side...
> Expression will be treated in a non-uniform way by attributes.
> Moreover, replacing a literal constant with a symbolic one will cause
> extension to stop working. Honestly, I cannot say if it is a big deal.
> But, I think it can be a surprise.

Would the situation be very different if we used a different syntax for 
attributes?

I expect extensions to document exactly which attributes are recognized 
and fail if the user does something wrong.

Example:

  type t =
   {
     foo: float [@xml digits 3];
     bar [@xml omit_if (fun s -> s = "")]: string;
   } [@@xml]


where the "xml" extension would specify something like:

"Within the type declaration, some special attributes are recognized on 
to customize the rendering of OCaml values as XML:

  - on type expressions:
    float [@xml digits N]  (where N is a integer literal)
                The float value is displayed with N digits
    date [@xml format "YYYY-MM-DD"]
                ...

  - on record fields:
    field[@xml omit_if <fun>]: ...
                Omit the XML element corresponding to the field if the
                provided function evaluates to false when passed the
                field value.
  ...
"

If we used, say, JSON as the attribute argument, the example would look 
like:

  type t =
   {
     foo: float [@xml {digits:3}];
     bar [@xml {omit_if:"(fun s -> s = \"\")"}]: string;
   } [@@xml]



Would that be really less confusing?

-- Alain


More information about the wg-camlp4 mailing list