[wg-camlp4] Structure/signature attributes suggestion

Gabriel Scherer gabriel.scherer at gmail.com
Fri Oct 11 18:26:14 BST 2013


I would count as one of the people not being fond of ';;'. However, there
is something I don't understand about your proposal: where in the AST tree
would you attach those floating attributes?

My understanding of Alain's ";;[@..]" was that he introduced a specific
"empty item" in the AST of the current structure/signature. Extending this
technique to the example you've shown would require adding such phony items
in a few more syntactic positions, which may or may not be a good idea.


On Fri, Oct 11, 2013 at 6:39 PM, Leo White <lpw25 at cam.ac.uk> wrote:

> Hi,
>
> I've been looking recently at encoding inline documentation
> (i.e. ocamldoc comments) within attributes, as part of my work on
> opam-doc. Mostly this works fine, but there is an issue with comments
> that are not attached to any item (e.g. section headers).
>
> I had thought that the existing support for "structure/signature
> attributes" would be sufficient. By these I mean attributes like:
>
>   ;;[@@doc "Hello World"]
>
> which are parsed as separate structure/signature items rather than
> attached to an existing structure/signature item.
>
> The problem is that unattached attributes can appear in a number of
> places that structure attributes cannot. Some examples:
>
>   type t = Foo of s
>
>   (** {3 Section} *)
>
>   and s = Bin of t option
>
>   class type foo = object
>     method a : int
>
>     (** Some comment *)
>
>     method b : int
>   end
>
> and so on.
>
> In both these cases it is hard to add support for structure items in
> those locations because that would require supporting ';;' in those
> locations as well.
>
> I have also heard a number of complaints about the ";;[@@ foo]"
> syntax. Firstly, that it is ugly and its meaning is not particularly
> obvious, and secondly that users may be confused when
>
>   type t;;
>   [@@ sexp]
>
> silently does not work.
>
> So my suggestion would be to (reluctantly) add a third form of
> attribute:
>
>   [@@@ foo]
>
> which means basically the same as:
>
>  ;;[@@ foo]
>
> does now. This could be supported in the additional locations that I
> mentioned above, and would allow for a syntax error for the ";;[@@sexp]"
> mistake.
>
> Since this follows the existing pattern of [@...] and [@@...], it should
> not be too much trouble to tell users about [@@@ ...], and certainly no
> worse than explaining ";;[@@...]" to them.
>
> Regards,
>
> Leo
> _______________________________________________
> wg-camlp4 mailing list
> wg-camlp4 at lists.ocaml.org
> http://lists.ocaml.org/listinfo/wg-camlp4
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/wg-camlp4/attachments/20131011/775ee0fe/attachment.html>


More information about the wg-camlp4 mailing list