{-|
Module      : Toml.Raw
Description : Raw expressions from a parsed TOML file
Copyright   : (c) Eric Mertens, 2023
License     : ISC
Maintainer  : emertens@gmail.com

This module provides a raw representation of TOML files as
a list of table definitions and key-value assignments.

These values use the raw dotted keys and have no detection
for overlapping assignments.

Further processing will happen in the "Semantics" module.

-}
module Toml.Parser.Types (
    Key,
    Expr(..),
    Val(..),
    SectionKind(..),
    ) where

import Data.List.NonEmpty (NonEmpty)
import Data.Time (Day, LocalTime, TimeOfDay, ZonedTime)
import Toml.Located (Located)

-- | Non-empty sequence of dotted simple keys
type Key = NonEmpty (Located String)

-- | Headers and assignments corresponding to lines of a TOML file
data Expr
    = KeyValExpr     Key Val -- ^ key value assignment: @key = value@
    | TableExpr      Key     -- ^ table: @[key]@
    | ArrayTableExpr Key     -- ^ array of tables: @[[key]]@
    deriving (ReadPrec [Expr]
ReadPrec Expr
Int -> ReadS Expr
ReadS [Expr]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Expr]
$creadListPrec :: ReadPrec [Expr]
readPrec :: ReadPrec Expr
$creadPrec :: ReadPrec Expr
readList :: ReadS [Expr]
$creadList :: ReadS [Expr]
readsPrec :: Int -> ReadS Expr
$creadsPrec :: Int -> ReadS Expr
Read, Int -> Expr -> ShowS
[Expr] -> ShowS
Expr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Expr] -> ShowS
$cshowList :: [Expr] -> ShowS
show :: Expr -> String
$cshow :: Expr -> String
showsPrec :: Int -> Expr -> ShowS
$cshowsPrec :: Int -> Expr -> ShowS
Show)

-- | Unvalidated TOML values. Table are represented as a list of
-- assignments rather than as resolved maps.
data Val
    = ValInteger   Integer
    | ValFloat     Double
    | ValArray     [Val]
    | ValTable     [(Key, Val)]
    | ValBool      Bool
    | ValString    String
    | ValTimeOfDay TimeOfDay
    | ValZonedTime ZonedTime
    | ValLocalTime LocalTime
    | ValDay       Day
    deriving (ReadPrec [Val]
ReadPrec Val
Int -> ReadS Val
ReadS [Val]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Val]
$creadListPrec :: ReadPrec [Val]
readPrec :: ReadPrec Val
$creadPrec :: ReadPrec Val
readList :: ReadS [Val]
$creadList :: ReadS [Val]
readsPrec :: Int -> ReadS Val
$creadsPrec :: Int -> ReadS Val
Read, Int -> Val -> ShowS
[Val] -> ShowS
Val -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Val] -> ShowS
$cshowList :: [Val] -> ShowS
show :: Val -> String
$cshow :: Val -> String
showsPrec :: Int -> Val -> ShowS
$cshowsPrec :: Int -> Val -> ShowS
Show)

-- | Kinds of table headers.
data SectionKind
    = TableKind -- ^ [table]
    | ArrayTableKind -- ^ [[array of tables]]
    deriving (ReadPrec [SectionKind]
ReadPrec SectionKind
Int -> ReadS SectionKind
ReadS [SectionKind]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SectionKind]
$creadListPrec :: ReadPrec [SectionKind]
readPrec :: ReadPrec SectionKind
$creadPrec :: ReadPrec SectionKind
readList :: ReadS [SectionKind]
$creadList :: ReadS [SectionKind]
readsPrec :: Int -> ReadS SectionKind
$creadsPrec :: Int -> ReadS SectionKind
Read, Int -> SectionKind -> ShowS
[SectionKind] -> ShowS
SectionKind -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SectionKind] -> ShowS
$cshowList :: [SectionKind] -> ShowS
show :: SectionKind -> String
$cshow :: SectionKind -> String
showsPrec :: Int -> SectionKind -> ShowS
$cshowsPrec :: Int -> SectionKind -> ShowS
Show, SectionKind -> SectionKind -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SectionKind -> SectionKind -> Bool
$c/= :: SectionKind -> SectionKind -> Bool
== :: SectionKind -> SectionKind -> Bool
$c== :: SectionKind -> SectionKind -> Bool
Eq)