Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camlp4 messes with comments #6

Open
ygrek opened this issue Dec 22, 2013 · 1 comment
Open

camlp4 messes with comments #6

ygrek opened this issue Dec 22, 2013 · 1 comment

Comments

@ygrek
Copy link
Member

ygrek commented Dec 22, 2013

From http://caml.inria.fr/mantis/view.php?id=4713 and http://caml.inria.fr/mantis/view.php?id=4346

Camlp4o messes with comments, hence with ocamldoc generation of documentation.

In order for comments to be used by ocamldoc, they should come immediately before or after a value. Camlp4o moves comments away from values, hence breaks ocamldoc.

Is there any hope that this could be fixed?

Examples :

$ cat tst.ml 
 (** comment of t *)
 type t =
   {
     mutable a : int; (** a *)
     mutable b : int; (** b *)
     mutable c : int; (** c *)
     mutable d : int; (** d *)
     mutable e : int; (** e *)
   }
 (** after *)
 $ camlp4o tst.ml 
 (** comment of t *)
 type t =
   { (** a *) (** b *) (** c *) mutable a : int; mutable b : int;
     mutable c : int; mutable d : int; (** d *) mutable e : int
   }
 cat tst_bis.ml
 (** comment of t *)
 type t =
   {
     mutable a : int; (** a *)
     mutable b : int; (** b *)
     mutable c : int; (** c *)
     mutable d : int; (** d *)
     mutable e : int; (** e *)
   }
 (** after *)
 ()
 $ camlp4o tst_bis.ml
 (** comment of t *)
 type t =
   { (** a *) (** b *) (** c *) mutable a : int; mutable b : int;
     mutable c : int; mutable d : int; (** d *) mutable e : int
   }
 (** e *)
 (** after *)
 let _ = ()

Old patch with partial fix :

diff --exclude=.svn -ur /home/ygrek/work/contrib/ocaml/3.11/camlp4/Camlp4/Printers/OCaml.ml camlp4/Camlp4/Printers/OCaml.ml
--- /home/ygrek/work/contrib/ocaml/3.11/camlp4/Camlp4/Printers/OCaml.ml 2009-10-31 13:58:04.000000000 +0200
+++ camlp4/Camlp4/Printers/OCaml.ml 2009-12-31 14:39:27.000000000 +0200
@@ -152,6 +152,13 @@
           do_print_comments_before loc f s
     | [: :] -> () ];

+  value rec do_print_all_comments loc f =
+    parser
+    [ [: ` (comm, comm_loc); s :] ->
+          let () = f comm comm_loc in
+          do_print_all_comments loc f s
+    | [: :] -> () ];
+
   class printer ?curry_constr:(init_curry_constr = False) ?(comments = True) () =
   object (o)

@@ -737,7 +744,7 @@
         <:sig_item< $<:sig_item<>>$; $sg$ >> ->
           o#sig_item f sg
       | <:sig_item< $sg1$; $sg2$ >> ->
-          do { o#sig_item f sg1; cut f; o#sig_item f sg2 }
+          do { o#sig_item f sg1; o#node f sg2 Ast.loc_of_sig_item; cut f; o#sig_item f sg2 }
       | <:sig_item< exception $t$ >> ->
           pp f "@[<2>exception@ %a%(%)@]" o#ctyp t semisep
       | <:sig_item< external $s$ : $t$ = $sl$ >> ->
@@ -1012,7 +1019,13 @@
       [ <:str_item< $exp:e$ >> -> pp f "@[<0>%a%(%)@]@." o#expr e semisep
       | st -> pp f "@[<v0>%a@]@." o#str_item st ];

-    method interf f sg = pp f "@[<v0>%a@]@." o#sig_item sg;
+    method interf f sg = 
+      let () = pp f "@[<v0>%a@]" o#sig_item sg in
+      let loc = Ast.loc_of_sig_item sg in
+      let () = do_print_all_comments loc (fun c _ -> pp f "%s@ " c)
+        (CommentFilter.take_stream comment_filter) in
+      pp f "@.";
+
   end;

   value with_outfile output_file fct arg =
@samoht
Copy link
Contributor

samoht commented Jan 22, 2014

+1

This is quite annoying (especially since we start having tools which extract and display the comments in a nice way).

avysk added a commit to avysk/lambda-term that referenced this issue May 8, 2014
When building documentation, OASIS runs all .mli files through camlp4o,
which messes with comments (camlp4/camlp4#6).
As a result, some API docs are corrupted (comments in wrong places,
comments missing). This patch introduces --enable-uglydocworkaround
configure option which forces API documentation to be rebuild, while
adding '-pp cat' to ocamldoc parameters. This causes multiple
'Warning: -pp overrides the effect of -syntax partly' as OASIS inserts
'-syntax camlp4o' in every ocamldoc call and works probably only by
accident but generates better documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants