realworldocaml / mdx

Execute code blocks inside your documentation
ISC License
269 stars 45 forks source link

Feature wish: better error messages around improper `;;` #454

Open ncik-roberts opened 3 months ago

ncik-roberts commented 3 months ago

Currently if you use ;; in the middle of an mdx code block you get an error, but only inconsistently:

This is OK:
```ocaml
type t = A;;
```_

This gives a parse error:
```ocaml
module M = struct
  type t = A;;
end
```_
```mdx-error
Error: Syntax error: 'end' expected
  This 'struct' might be unmatched
Error: Syntax error
```_

(The ```_s above are just meant to get github formatting to cooperate.)

I think mdx is chopping off input at the first ;; and attempting to parse it. Maybe it could generate a better error message and suggest removing the ;; if that is a suffix of the input.