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

Pretty print error location #390

Open
sim642 opened this issue Aug 19, 2022 · 2 comments
Open

Pretty print error location #390

sim642 opened this issue Aug 19, 2022 · 2 comments

Comments

@sim642
Copy link

sim642 commented Aug 19, 2022

In Drup/zarith-ppx#1 (comment) came up the point that mdx doesn't pretty print error locations like the OCaml toplevel does.
As a very random example, here it uses carets to point to the location span:

# let x = 1.2z;;
Line 1, characters 8-12:
1 | let x = 1.2z;;
            ^^^^
Error: Unknown modifier 'z' for literal 1.2z

(this is with TERM=dumb though; by default underlining is used, but that won't work in Markdown code blocks).

Currently mdx doesn't quote nor pretty print the location, producing output like:

# let x = 1.2z;;
Line 1, characters 8-12:
Error: Unknown modifier 'z' for literal 1.2z

Quoting duplicates the (single-line) input, which might be too verbose, so such behavior might have to be optional.

@Leonidas-from-XIV
Copy link
Collaborator

It's definitely a nice feature. The only thing that might be problematic (I haven't tested it yet) is that different OCaml compilers display this differently, which MDX would need to unify, since nobody likes their tests to fail because the ^^^^ are now in a slightly different spot.

I feel like this should be reasonably easy to add if we get the location information from the compiler.

@sim642
Copy link
Author

sim642 commented Aug 19, 2022

There's pp_loc, which might be more stable than compilers.

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