cats-parse
cats-parse copied to clipboard
add caret and spans like Trifecta (#234)
Resolves #234; adds Parser(0)#withCaret, span, withSpan
and Parser.caret
.
I'm unsure about the performance of these combinators but I expect it to be not very good. This is due to recomputation in LocationMap
each time the combinators are used. If this is much of a concern, this PR may be incapable. A probable optimization is to store the current Position
(incl. row, col) in the State
and update by need when the combinators are called (this is the approach of Megaparsec).
From Megaparsec's getSourcePos
combinator which functions alike:
Return the current source position. This function is not cheap, do not call it e.g. on matching of every token, that's a bad idea. Still you can use it to get
SourcePos
to attach to things that you parse.
Thanks for sending this PR! I think we will find a way to merge something close to this.
I am thinking about Span
. Do you think (Caret, Caret)
will be better than a separate datatype?
do you think you will be able to address the comments I left?
Sorry, I think I've been busy in August. I may be able to address them in September.
I'm planning to publish a new version soon if you have time to pick this back up.