(help) Accumulating errors with flatparse

hi! … so, i’m following the crafting interpreters online book, and i choose to do the parsing/scanning with the flatparse library.

anyways, when getting to the part of accumulating scanning errors (flatparse distinguishes failures and errors which terminate the parsing if not catched, so i thought of throwing an error, catching it, logging it and continuing parsing the rest), but i kinda hit a wall… flatparse doesnt support any custom state for its newtype ParserT (st :: ZeroBitType) e a type, (the library has an alternative parser with a minimal Int state and a Reader environment: newtype ParserT (st :: ZeroBitType) r e a )

so it occurred to me to create my own:

type Parser = ParserT PureMode
newtype Scanner err parsingRes = Scanner {getScanner :: WriterT (Vector err) (Parser err) parsingRes}
  deriving (Functor, Applicative, Monad, MonadWriter (Vector err))

but… i cannot use it because there’s no way to access the error from the ParserT type (my imagined api would be something like: withError :: Parser e a -> (e -> Parser e b) -> Parser e b, but it doesn’t exist).

anyways, because flatparse supports embedding IO/ST actions, it just occurred to me that i would use an MVar or similar, but i’d rather go with a pure approach (though i’m thinking, i gotta bite that bullet since i chose to use flatparse haha!)…

thank you in advance for any ideas/advice! :slight_smile: