Skip to content

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

@clembu

Description

@clembu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions