cats-parse icon indicating copy to clipboard operation
cats-parse copied to clipboard

add caret and spans like Trifecta (#234)

Open re-xyr opened this issue 3 years ago • 5 comments

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.

re-xyr avatar Jun 12 '21 14:06 re-xyr

Thanks for sending this PR! I think we will find a way to merge something close to this.

johnynek avatar Jun 14 '21 18:06 johnynek

I am thinking about Span. Do you think (Caret, Caret) will be better than a separate datatype?

re-xyr avatar Jun 15 '21 14:06 re-xyr

do you think you will be able to address the comments I left?

johnynek avatar Aug 18 '21 18:08 johnynek

Sorry, I think I've been busy in August. I may be able to address them in September.

re-xyr avatar Aug 19 '21 01:08 re-xyr

I'm planning to publish a new version soon if you have time to pick this back up.

johnynek avatar Oct 29 '21 23:10 johnynek