-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | TOML parser
--   
--   See README.md for details.
@package tomland
@version 0.3


-- | Contains general underlying monad for bidirectional TOML converion.
module Toml.Bi.Monad

-- | Monad for bidirectional Toml conversion. Contains pair of functions:
--   
--   <ol>
--   <li>How to read value of type <tt>a</tt> from immutable environment
--   context <tt>r</tt>?</li>
--   <li>How to store value of type <tt>a</tt> in stateful context
--   <tt>w</tt>?</li>
--   </ol>
--   
--   In practice instead of <tt>r</tt> we will use some <tt>Reader
--   Toml</tt> and instead of <tt>w</tt> we will use <tt>State Toml</tt>.
--   This approach with the bunch of utility functions allows to have
--   single description for from/to <tt>Toml</tt> conversion.
--   
--   In practice this type will always be used in the following way:
--   
--   <pre>
--   type <a>Bi</a> r w a = <a>Bijection</a> r w a a
--   </pre>
--   
--   Type parameter <tt>c</tt> if fictional. Here some trick is used. This
--   trick is implemented in <a>codec</a> and described in more details in
--   <a>related blog post</a>.
data Bijection r w c a
Bijection :: r a -> c -> w a -> Bijection r w c a

-- | Extract value of type <tt>a</tt> from monadic context <tt>r</tt>.
[biRead] :: Bijection r w c a -> r a

-- | Store value of type <tt>c</tt> inside monadic context <tt>w</tt> and
--   returning value of type <tt>a</tt>. Type of this function actually
--   should be <tt>a -&gt; w ()</tt> but with such type it's impossible to
--   have <a>Monad</a> and other instances.
[biWrite] :: Bijection r w c a -> c -> w a

-- | Specialized version of <a>Bijection</a> data type. This type alias is
--   used in practice.
type Bi r w a = Bijection r w a a

-- | This is an instance of <tt>Profunctor</tt> for <a>Bijection</a>. But
--   since there's no <tt>Profunctor</tt> type class in <tt>base</tt> or
--   package with no dependencies (and we don't want to bring extra
--   dependencies) this instance is implemented as a single top-level
--   function.
--   
--   Useful when you want to parse <tt>newtype</tt>s. For example, if you
--   had data type like this:
--   
--   <pre>
--   data Example = Example
--       { foo :: Bool
--       , bar :: Text
--       }
--   </pre>
--   
--   toml bidirectional converter for this type will look like this:
--   
--   <pre>
--   exampleT :: BiToml Example
--   exampleT = Example
--       <a>$</a> bool "foo" .= foo
--       <a>*</a> str  "bar" .= bar
--   </pre>
--   
--   Now if you change your time in the following way:
--   
--   <pre>
--   newtype Email = Email { unEmail :: Text }
--   
--   data Example = Example
--       { foo :: Bool
--       , bar :: Email
--       }
--   </pre>
--   
--   you need to patch your toml parser like this:
--   
--   <pre>
--   exampleT :: BiToml Example
--   exampleT = Example
--       <a>$</a> bool "foo" .= foo
--       <a>*</a> dimap unEmail Email (str  "bar") .= bar
--   </pre>
dimap :: (Functor r, Functor w) => (c -> d) -> (a -> b) -> Bijection r w d a -> Bijection r w c b

-- | Operator to connect two operations:
--   
--   <ol>
--   <li>How to get field from object?</li>
--   <li>How to write this field to toml?</li>
--   </ol>
--   
--   In code this should be used like this:
--   
--   <pre>
--   data Foo = Foo { fooBar :: Int, fooBaz :: String }
--   
--   foo :: BiToml Foo
--   foo = Foo
--    <a>$</a> int "bar" .= fooBar
--    <a>*</a> str "baz" .= fooBaz
--   </pre>
(.=) :: Bijection r w field a -> (object -> field) -> Bijection r w object a
infixl 5 .=
instance (GHC.Base.Functor r, GHC.Base.Functor w) => GHC.Base.Functor (Toml.Bi.Monad.Bijection r w c)
instance (GHC.Base.Applicative r, GHC.Base.Applicative w) => GHC.Base.Applicative (Toml.Bi.Monad.Bijection r w c)
instance (GHC.Base.Monad r, GHC.Base.Monad w) => GHC.Base.Monad (Toml.Bi.Monad.Bijection r w c)

module Toml.PrefixTree

-- | Data structure to represent table tree for <tt>toml</tt>.
data PrefixTree a
Leaf :: !Key -> !a -> PrefixTree a
Branch :: !Prefix -> !(Maybe a) -> !(PrefixMap a) -> PrefixTree a

-- | greatest common prefix
[bCommonPref] :: PrefixTree a -> !Prefix

-- | value by key = prefix
[bVal] :: PrefixTree a -> !(Maybe a)

-- | suffixes of prefix
[bPrefixMap] :: PrefixTree a -> !(PrefixMap a)

-- | Creates a <a>PrefixTree</a> of one key-value element.
singleT :: Key -> a -> PrefixTree a

-- | Inserts key-value element into the given <a>PrefixTree</a>.
insertT :: Key -> a -> PrefixTree a -> PrefixTree a

-- | Looks up the value at a key in the <a>PrefixTree</a>.
lookupT :: Key -> PrefixTree a -> Maybe a

-- | Converts <a>PrefixTree</a> to the list of pairs.
toListT :: PrefixTree a -> [(Key, a)]

-- | Map of layer names and corresponding <a>PrefixTree</a>s.
type PrefixMap a = HashMap Piece (PrefixTree a)

-- | Creates a <a>PrefixMap</a> of one key-value element.
single :: Key -> a -> PrefixMap a

-- | Inserts key-value element into the given <a>PrefixMap</a>.
insert :: Key -> a -> PrefixMap a -> PrefixMap a

-- | Looks up the value at a key in the <a>PrefixMap</a>.
lookup :: Key -> PrefixMap a -> Maybe a

-- | Constructs <a>PrefixMap</a> structure from the given list of
--   <a>Key</a> and value pairs.
fromList :: [(Key, a)] -> PrefixMap a

-- | Converts <a>PrefixMap</a> to the list of pairs.
toList :: PrefixMap a -> [(Key, a)]

-- | Represents the key piece of some layer.
newtype Piece
Piece :: Text -> Piece
[unPiece] :: Piece -> Text

-- | Key of value in <tt>key = val</tt> pair. Represents as non-empty list
--   of key components -- <a>Piece</a>s. Key like
--   
--   <pre>
--   site."google.com"
--   </pre>
--   
--   is represented like
--   
--   <pre>
--   Key (Piece "site" :| [Piece "\"google.com\""])
--   </pre>
newtype Key
Key :: NonEmpty Piece -> Key
[unKey] :: Key -> NonEmpty Piece

-- | Type synonym for <a>Key</a>.
type Prefix = Key
data KeysDiff

-- | Keys are equal
Equal :: KeysDiff

-- | Keys don't have any common part.
NoPrefix :: KeysDiff

-- | The first key is the prefix for the second one.
FstIsPref :: !Key -> KeysDiff
[diff] :: KeysDiff -> !Key

-- | The second key is the prefix for the first one.
SndIsPref :: !Key -> KeysDiff
[diff] :: KeysDiff -> !Key

-- | Key have same prefix.
Diff :: !Key -> !Key -> !Key -> KeysDiff
[pref] :: KeysDiff -> !Key
[diffFst] :: KeysDiff -> !Key
[diffSnd] :: KeysDiff -> !Key
instance GHC.Classes.Eq Toml.PrefixTree.KeysDiff
instance GHC.Show.Show Toml.PrefixTree.KeysDiff
instance GHC.Classes.Eq a => GHC.Classes.Eq (Toml.PrefixTree.PrefixTree a)
instance GHC.Show.Show a => GHC.Show.Show (Toml.PrefixTree.PrefixTree a)
instance GHC.Generics.Generic Toml.PrefixTree.Key
instance GHC.Base.Semigroup Toml.PrefixTree.Key
instance GHC.Classes.Ord Toml.PrefixTree.Key
instance GHC.Classes.Eq Toml.PrefixTree.Key
instance GHC.Show.Show Toml.PrefixTree.Key
instance Data.String.IsString Toml.PrefixTree.Piece
instance Data.Hashable.Class.Hashable Toml.PrefixTree.Piece
instance GHC.Classes.Ord Toml.PrefixTree.Piece
instance GHC.Classes.Eq Toml.PrefixTree.Piece
instance GHC.Show.Show Toml.PrefixTree.Piece
instance GHC.Base.Semigroup (Toml.PrefixTree.PrefixTree a)
instance Data.Hashable.Class.Hashable Toml.PrefixTree.Key
instance Data.String.IsString Toml.PrefixTree.Key

module Toml.Type.Value

-- | Needed for GADT parameterization
data TValue
TBool :: TValue
TInteger :: TValue
TDouble :: TValue
TText :: TValue
TDate :: TValue
TArray :: TValue
showType :: TValue -> String

-- | Value in <tt>key = value</tt> pair.
data Value (t :: TValue)

-- | Boolean value:
--   
--   <pre>
--   bool1 = true
--   bool2 = false
--   </pre>
[Bool] :: Bool -> Value  'TBool

-- | Integer value:
--   
--   <pre>
--   int1 = +99
--   int2 = 42
--   int3 = 0
--   int4 = -17
--   int5 = 5_349_221
--   hex1 = 0xDEADBEEF
--   oct2 = 0o755 # useful for Unix file permissions
--   bin1 = 0b11010110
--   </pre>
[Integer] :: Integer -> Value  'TInteger

-- | Floating point number:
--   
--   <pre>
--   flt1 = -3.1415   # fractional
--   flt2 = 1e6       # exponent
--   flt3 = 6.626e-34 # both
--   flt4 = 9_224_617.445_991_228_313
--   </pre>
[Double] :: Double -> Value  'TDouble

-- | String value:
--   
--   <pre>
--   key = "value"
--   bare_key = "value"
--   bare-key = "value"
--   </pre>
[Text] :: Text -> Value  'TText

-- | Date-time. See documentation for <a>DateTime</a> type.
[Date] :: DateTime -> Value  'TDate

-- | Array of values. According to TOML specification all values in array
--   should have the same type. This is guaranteed statically with this
--   type.
--   
--   <pre>
--   arr1 = [ 1, 2, 3 ]
--   arr2 = [ "red", "yellow", "green" ]
--   arr3 = [ [ 1, 2 ], [3, 4, 5] ]
--   arr4 = [ "all", <tt>strings</tt>, """are the same""", ''<tt>type''</tt>]
--   arr5 = [ [ 1, 2 ], ["a", "b", "c"] ]
--   
--   arr6 = [ 1, 2.0 ] # INVALID
--   </pre>
[Array] :: [Value t] -> Value  'TArray
data DateTime

-- | Offset date-time:
--   
--   <pre>
--   odt1 = 1979-05-27T07:32:00Z
--   odt2 = 1979-05-27T00:32:00-07:00
--   </pre>
Zoned :: !ZonedTime -> DateTime

-- | Local date-time (without offset):
--   
--   <pre>
--   ldt1 = 1979-05-27T07:32:00
--   ldt2 = 1979-05-27T00:32:00.999999
--   </pre>
Local :: !LocalTime -> DateTime

-- | Local date (only day):
--   
--   <pre>
--   ld1 = 1979-05-27
--   </pre>
Day :: !Day -> DateTime

-- | Local time (time of the day):
--   
--   <pre>
--   lt1 = 07:32:00
--   lt2 = 00:32:00.999999
--   </pre>
Hours :: !TimeOfDay -> DateTime
eqValueList :: [Value a] -> [Value b] -> Bool

-- | Reifies type of <a>Value</a> into <tt>ValueType</tt>. Unfortunately,
--   there's no way to guarante that <a>valueType</a> will return
--   <tt>t</tt> for object with type <tt>Value 't</tt>.
valueType :: Value t -> TValue

-- | Data type that holds expected vs. actual type.
data TypeMismatchError
TypeMismatchError :: TValue -> TValue -> TypeMismatchError
[typeExpected] :: TypeMismatchError -> TValue
[typeActual] :: TypeMismatchError -> TValue
sameValue :: Value a -> Value b -> Either TypeMismatchError (a :~: b)
instance GHC.Classes.Eq Toml.Type.Value.TypeMismatchError
instance GHC.Show.Show Toml.Type.Value.DateTime
instance GHC.Show.Show Toml.Type.Value.TValue
instance GHC.Classes.Eq Toml.Type.Value.TValue
instance GHC.Show.Show (Toml.Type.Value.Value t)
instance GHC.Show.Show Toml.Type.Value.TypeMismatchError
instance (t ~ 'Toml.Type.Value.TInteger) => GHC.Num.Num (Toml.Type.Value.Value t)
instance (t ~ 'Toml.Type.Value.TText) => Data.String.IsString (Toml.Type.Value.Value t)
instance GHC.Classes.Eq (Toml.Type.Value.Value t)
instance GHC.Classes.Eq Toml.Type.Value.DateTime

module Toml.Type.AnyValue

-- | Existential wrapper for <a>Value</a>.
data AnyValue
AnyValue :: (Value t) -> AnyValue

-- | Checks whether all elements inside given list of <a>AnyValue</a> have
--   the same type as given <a>Value</a>. Returns list of <tt>Value t</tt>
--   without given <a>Value</a>.
reifyAnyValues :: Value t -> [AnyValue] -> Either TypeMismatchError [Value t]
liftMatch :: (AnyValue -> Maybe a) -> (Value t -> Maybe a)

-- | Extract <a>Bool</a> from <a>Value</a>.
matchBool :: Value t -> Maybe Bool

-- | Extract <a>Integer</a> from <a>Value</a>.
matchInteger :: Value t -> Maybe Integer

-- | Extract <a>Double</a> from <a>Value</a>.
matchDouble :: Value t -> Maybe Double

-- | Extract <a>Text</a> from <a>Value</a>.
matchText :: Value t -> Maybe Text

-- | Extract <a>DateTime</a> from <a>Value</a>.
matchDate :: Value t -> Maybe DateTime

-- | Extract list of elements of type <tt>a</tt> from array.
matchArray :: (AnyValue -> Maybe a) -> Value t -> Maybe [a]
instance GHC.Show.Show Toml.Type.AnyValue.AnyValue
instance GHC.Classes.Eq Toml.Type.AnyValue.AnyValue

module Toml.Type.UValue

-- | Untyped value of <tt>TOML</tt>. You shouldn't use this type in your
--   code. Use <a>Value</a> instead.
data UValue
UBool :: !Bool -> UValue
UInteger :: !Integer -> UValue
UDouble :: !Double -> UValue
UText :: !Text -> UValue
UDate :: !DateTime -> UValue
UArray :: ![UValue] -> UValue

-- | Ensures that <a>UValue</a>s represents type-safe version of
--   <tt>toml</tt>.
typeCheck :: UValue -> Either TypeMismatchError AnyValue
instance GHC.Show.Show Toml.Type.UValue.UValue
instance GHC.Classes.Eq Toml.Type.UValue.UValue

module Toml.Type.TOML

-- | Represents TOML configuration value.
data TOML
TOML :: HashMap Key AnyValue -> PrefixMap TOML -> TOML
[tomlPairs] :: TOML -> HashMap Key AnyValue
[tomlTables] :: TOML -> PrefixMap TOML

-- | Inserts given key-value into the <a>TOML</a>.
insertKeyVal :: Key -> Value a -> TOML -> TOML

-- | Inserts given table into the <a>TOML</a>.
insertTable :: Key -> TOML -> TOML -> TOML
instance GHC.Classes.Eq Toml.Type.TOML.TOML
instance GHC.Show.Show Toml.Type.TOML.TOML
instance GHC.Base.Semigroup Toml.Type.TOML.TOML
instance GHC.Base.Monoid Toml.Type.TOML.TOML

module Toml.Type


-- | Naive implementation of data-prism approach.
module Toml.Prism

-- | Implementation of prism idea using simple data prism approach. Single
--   value of type <a>Prism</a> has two capabilities:
--   
--   <ol>
--   <li><a>preview</a>: first-class pattern-matching (deconstruct
--   <tt>object</tt> to possible <tt>field</tt>).</li>
--   <li><a>review</a>: constructor of <tt>object</tt> from
--   <tt>field</tt>.</li>
--   </ol>
data Prism object field
Prism :: object -> Maybe field -> field -> object -> Prism object field
[preview] :: Prism object field -> object -> Maybe field
[review] :: Prism object field -> field -> object

-- | Allows to match against given <a>Value</a> using provided prism for
--   <a>AnyValue</a>.
match :: Prism AnyValue a -> Value t -> Maybe a

-- | Creates prism for <a>AnyValue</a>.
mkAnyValuePrism :: (forall t. Value t -> Maybe a) -> (a -> Value tag) -> Prism AnyValue a

-- | <a>Bool</a> prism for <a>AnyValue</a>. Usually used with
--   <tt>arrayOf</tt> combinator.
_Bool :: Prism AnyValue Bool

-- | <a>Integer</a> prism for <a>AnyValue</a>. Usually used with
--   <tt>arrayOf</tt> combinator.
_Integer :: Prism AnyValue Integer

-- | <a>Double</a> prism for <a>AnyValue</a>. Usually used with
--   <tt>arrayOf</tt> combinator.
_Double :: Prism AnyValue Double

-- | <a>Text</a> prism for <a>AnyValue</a>. Usually used with
--   <tt>arrayOf</tt> combinator.
_Text :: Prism AnyValue Text

-- | <a>Array</a> prism for <a>AnyValue</a>. Usually used with
--   <tt>arrayOf</tt> combinator.
_Array :: Prism AnyValue a -> Prism AnyValue [a]

-- | Unsafe function for creating <a>Array</a> from list of
--   <a>AnyValue</a>. This function assumes that every element in this list
--   has the same type. Usually used when list of <a>AnyValue</a> is
--   created using single prism.
unsafeArray :: [AnyValue] -> Value  'TArray
instance Control.Category.Category Toml.Prism.Prism


-- | Contains functions for pretty printing <tt>toml</tt> types.
module Toml.Printer

-- | Converts <a>TOML</a> type into <a>Text</a>.
--   
--   For example, this
--   
--   <pre>
--   TOML
--       { tomlPairs  = HashMap.fromList [(Key "title", String "TOML example")]
--       , tomlTables = HashMap.fromList
--             [( TableId (NonEmpty.fromList ["example", "owner"])
--              , TOML
--                    { tomlPairs  = HashMap.fromList [(Key "name", String <a>Kowainik</a>)]
--                    , tomlTables = mempty
--                    , tomlTableArrays = mempty
--                    }
--              )]
--       , tomlTableArrays = mempty
--       }
--   </pre>
--   
--   will be translated to this
--   
--   <pre>
--   title = "TOML Example"
--   
--   [example.owner]
--     name = <a>Kowainik</a>
--   </pre>
prettyToml :: TOML -> Text

-- | Converts <a>TOML</a> into <a>Text</a> with the given indent.
prettyTomlInd :: Int -> Text -> TOML -> Text


-- | Parser of TOML language. Implemented with the help of
--   <tt>megaparsec</tt> package.
module Toml.Parser

-- | Pretty parse exception for parsing toml.
newtype ParseException
ParseException :: Text -> ParseException

-- | Parses <a>Text</a> as <a>TOML</a> object.
parse :: Text -> Either ParseException TOML
arrayP :: Parser [UValue]
boolP :: Parser Bool
doubleP :: Parser Double
integerP :: Parser Integer
keyP :: Parser Key
keyValP :: Parser (Key, AnyValue)
textP :: Parser Text
tableHeaderP :: Parser (Key, TOML)
tomlP :: Parser TOML
instance GHC.Classes.Eq Toml.Parser.ParseException
instance GHC.Show.Show Toml.Parser.ParseException


-- | This module introduces EDSL for manually specifying <a>TOML</a> data
--   types.
--   
--   <b>Example:</b>
--   
--   <pre>
--   exampleToml :: TOML
--   exampleToml = mkToml $ do
--       "key1" =: 1
--       "key2" =: Bool True
--       table "tableName" $
--           "tableKey" =: Array [<a>Oh</a>, <a>Hi</a>, <a>Mark</a>]
--   </pre>
module Toml.Edsl

-- | Creates <a>TOML</a> from the <a>TDSL</a>.
mkToml :: TDSL -> TOML

-- | Adds key-value pair to the <a>TDSL</a>.
(=:) :: Key -> Value a -> TDSL

-- | Adds table to the <a>TDSL</a>.
table :: Key -> TDSL -> TDSL

module Toml.Bi.Code

-- | Specialied <a>Bi</a> type alias for <tt>Toml</tt> monad. Keeps
--   <a>TOML</a> object either as environment or state.
type BiToml a = Bi Env St a

-- | Immutable environment for <tt>Toml</tt> conversion. This is <tt>r</tt>
--   type variable in <a>Bijection</a> data type.
type Env = ExceptT DecodeException (Reader TOML)

-- | Mutable context for <tt>Toml</tt> conversion. This is <tt>w</tt> type
--   variable in <a>Bijection</a> data type.
type St = State TOML

-- | Type of exception for converting from <tt>Toml</tt> to user custom
--   data type.
data DecodeException

-- | No such key
KeyNotFound :: Key -> DecodeException

-- | No such table
TableNotFound :: Key -> DecodeException

-- | Expected type vs actual type
TypeMismatch :: Key -> Text -> TValue -> DecodeException

-- | Exception during parsing
ParseError :: ParseException -> DecodeException

-- | Converts <a>DecodeException</a> into pretty human-readable text.
prettyException :: DecodeException -> Text

-- | Convert textual representation of toml into user data type.
decode :: BiToml a -> Text -> Either DecodeException a

-- | Convert object to textual representation.
encode :: BiToml a -> a -> Text
instance GHC.Show.Show Toml.Bi.Code.DecodeException
instance GHC.Classes.Eq Toml.Bi.Code.DecodeException


-- | Contains TOML-specific combinators for converting between TOML and
--   user data types.
module Toml.Bi.Combinators

-- | General function to create bidirectional converters for values.
bijectionMaker :: forall a t. Typeable a => (forall f. Value f -> Maybe a) -> (a -> Value t) -> Key -> BiToml a

-- | Helper dimapper to turn <a>integer</a> parser into parser for
--   <a>Int</a>, <tt>Natural</tt>, <a>Word</a>, etc.
dimapNum :: forall n r w. (Integral n, Functor r, Functor w) => Bi r w Integer -> Bi r w n

-- | Almost same as <a>dimap</a>. Useful when you want to have fields like
--   this inside your configuration:
--   
--   <pre>
--   data GhcVer = Ghc7103 | Ghc802 | Ghc822 | Ghc842
--   
--   showGhcVer  :: GhcVer -&gt; Text
--   parseGhcVer :: Text -&gt; Maybe GhcVer
--   </pre>
--   
--   When you specify couple of functions of the following types:
--   
--   <pre>
--   show  :: a -&gt; Text
--   parse :: Text -&gt; Maybe a
--   </pre>
--   
--   they should satisfy property <tt>parse . show == Just</tt> if you want
--   to use your converter for pretty-printing.
mdimap :: (Monad r, Monad w, MonadError DecodeException r) => (c -> d) -> (a -> Maybe b) -> Bijection r w d a -> Bijection r w c b

-- | Parser for boolean values.
bool :: Key -> BiToml Bool

-- | Parser for integer values.
int :: Key -> BiToml Int

-- | Parser for integer values.
integer :: Key -> BiToml Integer

-- | Parser for floating values.
double :: Key -> BiToml Double

-- | Parser for string values.
text :: Key -> BiToml Text

-- | Parser for array of values. Takes converter for single array element
--   and returns list of values.
arrayOf :: forall a. Typeable a => Prism AnyValue a -> Key -> BiToml [a]

-- | Bidirectional converter for <tt>Maybe smth</tt> values.
maybeT :: forall a. (Key -> BiToml a) -> Key -> BiToml (Maybe a)

-- | Parser for tables. Use it when when you have nested objects.
table :: forall a. BiToml a -> Key -> BiToml a


-- | Reexports functions under <tt>Toml.Bi.*</tt>.
module Toml.Bi


-- | This module reexports all functionality of <tt>tomland</tt> package.
--   It's suggested to import this module qualified, like this:
--   
--   <pre>
--   import qualified Toml
--   </pre>
module Toml
