Whiteknight / ParserObjects

C# library for parser combinators
https://whiteknight.github.io/ParserObjects
Apache License 2.0
6 stars 0 forks source link

IResult -> struct Result #172

Closed Whiteknight closed 1 year ago

Whiteknight commented 1 year ago

There's a lot of unnecessary heap object allocation in results. We should be able to use a struct for most cases.

Since there are a few places where the difference between Result and Result would matter, we may need two structs (with a conversion in between).

Whiteknight commented 1 year ago

I started some of this work in a branch but have taken a break to reconsider. We're going to lose type covariance on IParser<TInput, TOutput> which might cause problems down the road. Plus the size of the result struct is relatively large, and changes to how we create and propagate them are worth some consideration

Whiteknight commented 1 year ago

This isn't going to work as envisioned, because the lose of contravariance on the output type of the parser causes too many problems. Also with the advent of .Match() in the parsers, we have an optimized way to test a parser without a heap allocation. I'm closing this for now. I can reopen later if I find a new possible way forward.