{-# LANGUAGE FlexibleContexts #-}

module Data.Medea.Parser.Spec.Schemata
  ( Specification (..),
    parseSpecification,
  )
where

import qualified Data.Medea.Parser.Spec.Schema as Schema
import Data.Medea.Parser.Types (MedeaParser)
import Data.Vector (Vector)
import qualified Data.Vector as V
import Text.Megaparsec (MonadParsec (..), sepBy1)
import Text.Megaparsec.Char (eol)

newtype Specification = Specification (Vector Schema.Specification)

parseSpecification :: MedeaParser Specification
parseSpecification :: MedeaParser Specification
parseSpecification = do
  [Specification]
specs <- MedeaParser Specification
Schema.parseSpecification MedeaParser Specification
-> ParsecT ParseError Text Identity Text
-> ParsecT ParseError Text Identity [Specification]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepBy1` ParsecT ParseError Text Identity Text
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Tokens s)
eol
  ParsecT ParseError Text Identity ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof
  Specification -> MedeaParser Specification
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Specification -> MedeaParser Specification)
-> ([Specification] -> Specification)
-> [Specification]
-> MedeaParser Specification
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector Specification -> Specification
Specification (Vector Specification -> Specification)
-> ([Specification] -> Vector Specification)
-> [Specification]
-> Specification
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Specification] -> Vector Specification
forall a. [a] -> Vector a
V.fromList ([Specification] -> MedeaParser Specification)
-> [Specification] -> MedeaParser Specification
forall a b. (a -> b) -> a -> b
$ [Specification]
specs