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

Interop with StdLib.Lexing and compiler-libs' Location #88

Open
clembu opened this issue Nov 9, 2019 · 1 comment
Open

Interop with StdLib.Lexing and compiler-libs' Location #88

clembu opened this issue Nov 9, 2019 · 1 comment

Comments

@clembu
Copy link

clembu commented Nov 9, 2019

Ocaml's own compiler libraries provide cool ways to highlight source code and display syntax errors, through Location.print_report.

I managed to use it to display Menhir's messages with the location:

File "test_input", line 5, characters 9-10:
Error: Headers must not have trailing markers

But if I want it to have source highlighting like so:

File "inkc/lib/lexer.ml", line 13, characters 33-38:
13 | let any_blank = [%sedlex.regexp? blank | newline]
                                      ^^^^^
Error: Sedlex: unbound regexp blank

then I have to give it a Lexing.lexbuf instance with Location.input_buf := ...

It'd be nice if Sedlex had buffer conversion out of the box to support this.

As it is now, I can't even create a Lexing.lexbuf myself out of a Sedlexing.lexbuf because I don't have access to the buffer's actual contents. All I can get are locations. And small bits of the contents through the lexeme functions

@hhugo
Copy link
Contributor

hhugo commented Feb 25, 2023

You should be able to get it work by setting Location.input_buf := None. Reading from an existing lexbuf seems to be an optimization only.

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