Whiteknight / ParserObjects

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

Add simplified Transform parser variant #178

Closed Whiteknight closed 1 year ago

Whiteknight commented 1 year ago

The current Transform parser passes the current parse state to the user, which can use it to make any arbitrary change to the parse state or parse result. This causes serious problems because, for example, Match() cannot be optimized in any meaningful way, and we cannot reason about the effects and side-effects of .Parse() without knowing the contents of the user callback.

We need to decide:

  1. Do we really want Transform to have this much power? Is there a reason why we need the parse state and the input sequence provided there?
  2. If so, consider creating a Transform parser variant which only operates on result values (and can be optimized and reasoned about, because it won't change state or consume input)
Whiteknight commented 1 year ago

I am simplifying Transform to only operate on result values. The transform callback will not have access to the IParseState<TInput> or other contextual/state data, and cannot make modifications to the input sequence. The TransformErrorResult and TransformResult parsers are disappearing as part of this work. (We might re-add the former in some capacity, if a real use-case can be found).