Skip to content

PV is not true to its name

The idea behind a PV (a parser-validator) is that it's a disambiguation pass which can fail and add annotations but never consume any input. However, its current definition is tightly coupled with P and nothing in it says that it cannot consume input:

newtype PV a = PV (ReaderT SDoc P a)
  deriving (Functor, Applicative, Monad)

It would be less confusing to define PV independently from P, something along these lines:

data PV_State =
  PV_State
    { pv_messages :: SDoc -> DynFlags -> Messages
    , pv_annotations :: [(ApiAnnKey,[SrcSpan])]
    , pv_options :: ParserFlags
    }
newtype PV a = PV (PV_State -> (PV_State, Maybe a))

While more verbose, it does not conflate the notions of P and PV, and PV_State is a much smaller accumulator to carry around, actually making PV easier to understand as there are less fields involved.

Most importantly, buffer :: StringBuffer is a part of PState but not PV_State, which is evidence that PV cannot read raw input.

Edited by Vladislav Zavialov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information