-- |
-- License: GPL-3.0-or-later
-- Copyright: Oleg Grenrus
{-# LANGUAGE OverloadedStrings #-}
module CabalFmt.Fields.Extensions (
    otherExtensionsF,
    defaultExtensionsF,
    ) where

import qualified Distribution.Parsec          as C
import qualified Distribution.Parsec.Newtypes as C
import qualified Distribution.Pretty          as C
import qualified Language.Haskell.Extension   as C
import qualified Text.PrettyPrint             as PP

import CabalFmt.Prelude
import CabalFmt.Fields

otherExtensionsF :: FieldDescrs () ()
otherExtensionsF :: FieldDescrs () ()
otherExtensionsF = FieldName
-> ([Extension] -> Doc)
-> (forall (m :: * -> *). CabalParsing m => m [Extension])
-> FieldDescrs () ()
forall f s a.
FieldName
-> (f -> Doc)
-> (forall (m :: * -> *). CabalParsing m => m f)
-> FieldDescrs s a
singletonF FieldName
"other-extensions" [Extension] -> Doc
pretty forall (m :: * -> *). CabalParsing m => m [Extension]
parse

defaultExtensionsF :: FieldDescrs () ()
defaultExtensionsF :: FieldDescrs () ()
defaultExtensionsF = FieldName
-> ([Extension] -> Doc)
-> (forall (m :: * -> *). CabalParsing m => m [Extension])
-> FieldDescrs () ()
forall f s a.
FieldName
-> (f -> Doc)
-> (forall (m :: * -> *). CabalParsing m => m f)
-> FieldDescrs s a
singletonF FieldName
"default-extensions" [Extension] -> Doc
pretty forall (m :: * -> *). CabalParsing m => m [Extension]
parse

parse :: C.CabalParsing m => m [C.Extension]
parse :: m [Extension]
parse = ([Extension] -> List FSep (MQuoted Extension) Extension)
-> List FSep (MQuoted Extension) Extension -> [Extension]
forall o n. Newtype o n => (o -> n) -> n -> o
unpack' (FSep
-> (Extension -> MQuoted Extension)
-> [Extension]
-> List FSep (MQuoted Extension) Extension
forall sep a b. sep -> (a -> b) -> [a] -> List sep b a
C.alaList' FSep
C.FSep Extension -> MQuoted Extension
forall a. a -> MQuoted a
C.MQuoted) (List FSep (MQuoted Extension) Extension -> [Extension])
-> m (List FSep (MQuoted Extension) Extension) -> m [Extension]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (List FSep (MQuoted Extension) Extension)
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
C.parsec

pretty :: [C.Extension] -> PP.Doc
pretty :: [Extension] -> Doc
pretty = [Doc] -> Doc
PP.vcat ([Doc] -> Doc) -> ([Extension] -> [Doc]) -> [Extension] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Extension -> Doc) -> [Extension] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Extension -> Doc
forall a. Pretty a => a -> Doc
C.pretty ([Extension] -> [Doc])
-> ([Extension] -> [Extension]) -> [Extension] -> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Extension -> String) -> [Extension] -> [Extension]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn Extension -> String
forall a. Show a => a -> String
show