
--- ENVIRONMENT MANAGEMENT ---
type EnvParser = StateT Env Parser

parseEnv :: EnvParser a -> BS -> Either String (Env, BS)
parseEnv f = toEither `o` parse $ runStateT f initialEnv
    where toEither (Fail{})    = Left "Header parsing failure"
          toEither (Partial _) = Left "Consumed all input while parsed header"
          toEither (Done r (_, env)) = Right (env, r)