Skip to content

Add stream to Parser.Error, enabling nicer error messages.#125

Open
AmosNico wants to merge 1 commit into
fgdorais:mainfrom
AmosNico:error-with-stream
Open

Add stream to Parser.Error, enabling nicer error messages.#125
AmosNico wants to merge 1 commit into
fgdorais:mainfrom
AmosNico:error-with-stream

Conversation

@AmosNico

@AmosNico AmosNico commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Add the stream to Parser.Error as follows:

protected class Parser.Error (ε σ : Type _) (τ : outParam (Type _)) [Parser.Stream σ τ] where
  unexpected : σ → Stream.Position σ → Option τ → ε
  addMessage : ε → σ → Stream.Position σ → String → ε

This makes it possible to use (parts of) the stream when displaying error messages. This is particular useful in string parsers, where it would enable displaying the line where the error occurred. While I have not tested performance yet, I expect that the change should not effect performance to much, assuming that the underlying stream is not modified.
This is especially the case for #124, but even without this pr I think at most some references to the underlying String/Array/... and some positions will be duplicated.

If there is interest, I would be happy to make a pr adding nicer error formatting for string parsers to the library.

… output (parts of) the stream when displaying error messages.
@AmosNico AmosNico force-pushed the error-with-stream branch from 1ba4010 to ebabfcf Compare July 14, 2026 11:17
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

Successfully merging this pull request may close these issues.

1 participant