realworldocaml/mdx

spurious `;;` are added

c-cube opened this issue · 3 comments

I have lines like:

# v;; (* now v is a mutable vector *)
- : (int, CCVector.rw) CCVector.t = <abstr>

and mdx now gives me a diff like:


-# v;; (* now v is a mutable vector *)
+# v;; (* now v is a mutable vector *);;
 - : (int, CCVector.rw) CCVector.t = <abstr>

(to reproduce, make test in https://github.com/c-cube/ocaml-containers )

As of 2.0, it is recommended that MDX toplevel phrases are ;; terminated. If the phrase is valid but not ;; terminated it will add them in the output. In 3.0 we'll refuse non ;; terminated phrases as input.

This example is indeed a bug and we need to fix it. What I'm not sure is what the right fix is, and my first impression is that it would reject your phrase, or rather reject the comment which is neither part of the phrase itself nor part of the toplevel output.
I'm a bit surprised your initial example used to work in the first place and would consider it a bug on our side to accept it.

Would it be acceptable for you to put the comment inside the phrase in such a fashion:

# v (* now v is a mutable vector *);;
- : (int, CCVector.rw) CCVector.t = <abstr>

Another option would be to make the comment part of the document rather than the block, if the above syntax doesn't quite suit you:

```ocaml
# (* some previous code *) ...
...
```
Now v is a mutable vector:
```ocaml
# v;;
- : (int, CCVector.rw) CCVector.t = <abstr>
```

With #398 this issue could be solved.