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

Gabriel Scherer gabriel.scherer at gmail.com
Fri Mar 1 13:40:22 GMT 2013


I'm not fond of having "with" as a special case. If you don't support
the type-conv or deriving syntax as is, could we take this as an
opportunity to go back to an uniform syntax? Type declaration could be
handled like any structure item.

Don't we want to have attributes on signature items as well?

Finally, I bet the non-terminal ".." will get little love, but I'm
sure you considered other option (for example just ;;(:foo), but that
doesn't work in the toplevel and we really want ";;" to help *avoid*
precedence issues) and trust that this is one of the less ugly ones.

Is that proposal sufficient to do ocamldoc with structured attributes
rather than comments? It looks like it is. Can an annotation node, by
itself, stand as a structure item (I'm thinking section comments)?

On Fri, Mar 1, 2013 at 2:05 PM, Alain Frisch <alain.frisch at lexifi.com> wrote:
> On 03/01/2013 09:08 AM, Mark Shinwell wrote:
>>
>> 1. If possible, I'd rather see one new syntactic form, rather than
>> three.
>
>
> I've made the syntax more uniform, dropped prefix attributes, and added
> attributes on type declarations.
>
> The current syntax is:
>
> Attributes:
>
>   On expressions:         expr (:foo expr)
>   On type expressions:    type (:foo expr)
>   On structure items:     str_item ..(:foo expr)
>   On type declarations:   type t = ... with (:foo1 expr1) (:foo2 expr2)
>
> Extension nodes:
>
>   On expressions:         (&foo expr)
>   On type expressions:    (&foo expr)
>   On structure items:     ..(&foo expr)
>
>
> A type-conv like example (attributes on type expressions and type
> declarations):
>
>
> =================================================
>  type t = {
>     x : int (:default 42);
>     y : int (:default 3) (:sexp_drop_default);
>     z : int (:default 3) (:sexp_drop_if z_test);
>  } with (:sexp)
> =================================================
>
>
> A Bisect-like example (attributes on expressions and structure items):
>
> =================================================
> let f x =
>   match List.map foo [x; a x; b x] with
>   | [y1; y2; y3] -> tata
>   | _ -> (assert false) (:bisect visit)
>
>
> let unused = ()
> ..(:bisect ignore)
> =================================================
>
>
> A Bolt-like example (extension nodes on expressions):
>
> =================================================
> let funct n =
>   (&log) "funct(%d)" n LEVEL DEBUG;
>   for i = 1 to n do
>     print_endline "..."
>   done
> =================================================
>
> or:
>
> =================================================
> let funct n =
>   (&log "funct(%d)" n LEVEL DEBUG);
>   for i = 1 to n do
>     print_endline "..."
>   done
> =================================================
>
>
> A map/fold generator (extension nodes on structure item):
>
> =================================================
> type variable = string
>  and term =
>   | Var of variable
>   | Lam of variable * term
>   | App of term * term
>
>
> ..(&generate_map map term)
> =================================================
>
> or, if we also add extension nodes on class expressions:
>
> =================================================
> type variable = string
>  and term =
>   | Var of variable
>   | Lam of variable * term
>   | App of term * term
>
>
> class map = (&generate_map term)
> =================================================
>
>
>
> -- 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