module CabalGild.Extra.FieldLine where

import qualified Data.ByteString as ByteString
import qualified Distribution.Fields as Fields
import qualified Distribution.Parsec.FieldLineStream as FieldLineStream

-- | Extracts the annotation of a 'Fields.FieldLine'.
annotation :: Fields.FieldLine a -> a
annotation :: forall a. FieldLine a -> a
annotation (Fields.FieldLine a
x ByteString
_) = a
x

-- | Extracts the value of a 'Fields.FieldLine'.
value :: Fields.FieldLine a -> ByteString.ByteString
value :: forall a. FieldLine a -> ByteString
value (Fields.FieldLine a
_ ByteString
x) = ByteString
x

-- | Converts a list of 'Fields.FieldLine's into a
-- 'FieldLineStream.FieldLineStream'.
toFieldLineStream :: [Fields.FieldLine a] -> FieldLineStream.FieldLineStream
toFieldLineStream :: forall a. [FieldLine a] -> FieldLineStream
toFieldLineStream [FieldLine a]
fls = case [FieldLine a]
fls of
  [] -> ByteString -> FieldLineStream
FieldLineStream.FLSLast ByteString
ByteString.empty
  [FieldLine a
x] -> ByteString -> FieldLineStream
FieldLineStream.FLSLast (ByteString -> FieldLineStream) -> ByteString -> FieldLineStream
forall a b. (a -> b) -> a -> b
$ FieldLine a -> ByteString
forall a. FieldLine a -> ByteString
value FieldLine a
x
  FieldLine a
x : [FieldLine a]
xs -> ByteString -> FieldLineStream -> FieldLineStream
FieldLineStream.FLSCons (FieldLine a -> ByteString
forall a. FieldLine a -> ByteString
value FieldLine a
x) (FieldLineStream -> FieldLineStream)
-> FieldLineStream -> FieldLineStream
forall a b. (a -> b) -> a -> b
$ [FieldLine a] -> FieldLineStream
forall a. [FieldLine a] -> FieldLineStream
toFieldLineStream [FieldLine a]
xs