{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Data.SemanticVersion.BuildIdentifiers where

import Control.Lens
import Data.List.NonEmpty
import Data.SemanticVersion.BuildIdentifier
import Text.Parser.Char
import Text.Parser.Combinators

-- $setup
-- >>> import Text.Parsec(parse)
-- >>> import Data.Either(isLeft)

-- <dot-separated build identifiers> ::= <build identifier>
--                                     | <build identifier> "." <dot-separated build identifiers>
newtype BuildIdentifiers =
  BuildIdentifiers (NonEmpty BuildIdentifier)
  deriving (BuildIdentifiers -> BuildIdentifiers -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildIdentifiers -> BuildIdentifiers -> Bool
$c/= :: BuildIdentifiers -> BuildIdentifiers -> Bool
== :: BuildIdentifiers -> BuildIdentifiers -> Bool
$c== :: BuildIdentifiers -> BuildIdentifiers -> Bool
Eq, Int -> BuildIdentifiers -> ShowS
[BuildIdentifiers] -> ShowS
BuildIdentifiers -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildIdentifiers] -> ShowS
$cshowList :: [BuildIdentifiers] -> ShowS
show :: BuildIdentifiers -> String
$cshow :: BuildIdentifiers -> String
showsPrec :: Int -> BuildIdentifiers -> ShowS
$cshowsPrec :: Int -> BuildIdentifiers -> ShowS
Show)

class HasBuildIdentifiers a where
  buildIdentifiers ::
    Lens' a BuildIdentifiers

instance HasBuildIdentifiers BuildIdentifiers where
  buildIdentifiers :: Lens' BuildIdentifiers BuildIdentifiers
buildIdentifiers =
    forall a. a -> a
id

class AsBuildIdentifiers a where
  _BuildIdentifiers ::
    Prism' a BuildIdentifiers

instance AsBuildIdentifiers BuildIdentifiers where
  _BuildIdentifiers :: Prism' BuildIdentifiers BuildIdentifiers
_BuildIdentifiers =
    forall a. a -> a
id

instance BuildIdentifiers ~ t => Rewrapped BuildIdentifiers t

instance Wrapped BuildIdentifiers where
  type Unwrapped BuildIdentifiers = NonEmpty BuildIdentifier
  _Wrapped' :: Iso' BuildIdentifiers (Unwrapped BuildIdentifiers)
_Wrapped' =
    forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
      (\(BuildIdentifiers NonEmpty BuildIdentifier
x) -> NonEmpty BuildIdentifier
x)
      NonEmpty BuildIdentifier -> BuildIdentifiers
BuildIdentifiers

parseBuildIdentifiers ::
  CharParsing p =>
  p BuildIdentifiers
parseBuildIdentifiers :: forall (p :: * -> *). CharParsing p => p BuildIdentifiers
parseBuildIdentifiers =
  NonEmpty BuildIdentifier -> BuildIdentifiers
BuildIdentifiers forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a sep.
Alternative m =>
m a -> m sep -> m (NonEmpty a)
sepByNonEmpty forall (p :: * -> *). CharParsing p => p BuildIdentifier
parseBuildIdentifier (forall (m :: * -> *). CharParsing m => Char -> m Char
char Char
'.')