module BishBosh.Input.PGNOptions(
PGNOptions(
getDatabaseFilePath,
getIsStrictlySequential,
getValidateMoves,
getTextEncoding,
getIdentificationTags,
getMinimumPlies
),
tag,
databaseFilePathTag,
mkPGNOptions
) where
import qualified BishBosh.Component.Move as Component.Move
import qualified BishBosh.ContextualNotation.PGN as ContextualNotation.PGN
import qualified BishBosh.ContextualNotation.StandardAlgebraic as ContextualNotation.StandardAlgebraic
import qualified BishBosh.Data.Exception as Data.Exception
import qualified BishBosh.Text.Encoding as Text.Encoding
import qualified BishBosh.Text.ShowList as Text.ShowList
import qualified Control.DeepSeq
import qualified Control.Exception
import qualified Data.Default
import qualified System.FilePath
import qualified System.IO
import qualified Text.XML.HXT.Arrow.Pickle as HXT
import qualified ToolShed.Data.Foldable
tag :: String
tag :: String
tag = String
"pgnOptions"
databaseFilePathTag :: String
databaseFilePathTag :: String
databaseFilePathTag = String
"databaseFilePath"
validateMovesTag :: String
validateMovesTag :: String
validateMovesTag = String
"validateMoves"
isStrictlySequentialTag :: String
isStrictlySequentialTag :: String
isStrictlySequentialTag = String
"isStrictlySequential"
identificationTagTag :: String
identificationTagTag :: String
identificationTagTag = String
"identificationTag"
minimumPliesTag :: String
minimumPliesTag :: String
minimumPliesTag = String
"minimumPlies"
data PGNOptions = MkPGNOptions {
PGNOptions -> String
getDatabaseFilePath :: System.FilePath.FilePath,
PGNOptions -> IsStrictlySequential
getIsStrictlySequential :: ContextualNotation.PGN.IsStrictlySequential,
PGNOptions -> IsStrictlySequential
getValidateMoves :: ContextualNotation.StandardAlgebraic.ValidateMoves,
PGNOptions -> TextEncoding
getTextEncoding :: System.IO.TextEncoding,
PGNOptions -> [String]
getIdentificationTags :: [ContextualNotation.PGN.Tag],
PGNOptions -> NMoves
getMinimumPlies :: Component.Move.NMoves
} deriving PGNOptions -> PGNOptions -> IsStrictlySequential
(PGNOptions -> PGNOptions -> IsStrictlySequential)
-> (PGNOptions -> PGNOptions -> IsStrictlySequential)
-> Eq PGNOptions
forall a.
(a -> a -> IsStrictlySequential)
-> (a -> a -> IsStrictlySequential) -> Eq a
/= :: PGNOptions -> PGNOptions -> IsStrictlySequential
$c/= :: PGNOptions -> PGNOptions -> IsStrictlySequential
== :: PGNOptions -> PGNOptions -> IsStrictlySequential
$c== :: PGNOptions -> PGNOptions -> IsStrictlySequential
Eq
instance Control.DeepSeq.NFData PGNOptions where
rnf :: PGNOptions -> ()
rnf MkPGNOptions {
getDatabaseFilePath :: PGNOptions -> String
getDatabaseFilePath = String
databaseFilePath,
getIsStrictlySequential :: PGNOptions -> IsStrictlySequential
getIsStrictlySequential = IsStrictlySequential
isStrictlySequential,
getValidateMoves :: PGNOptions -> IsStrictlySequential
getValidateMoves = IsStrictlySequential
validateMoves,
getIdentificationTags :: PGNOptions -> [String]
getIdentificationTags = [String]
identificationTags,
getMinimumPlies :: PGNOptions -> NMoves
getMinimumPlies = NMoves
minimumPlies
} = (String, IsStrictlySequential, IsStrictlySequential, [String],
NMoves)
-> ()
forall a. NFData a => a -> ()
Control.DeepSeq.rnf (String
databaseFilePath, IsStrictlySequential
isStrictlySequential, IsStrictlySequential
validateMoves, [String]
identificationTags, NMoves
minimumPlies)
instance Show PGNOptions where
showsPrec :: NMoves -> PGNOptions -> ShowS
showsPrec NMoves
_ MkPGNOptions {
getDatabaseFilePath :: PGNOptions -> String
getDatabaseFilePath = String
databaseFilePath,
getIsStrictlySequential :: PGNOptions -> IsStrictlySequential
getIsStrictlySequential = IsStrictlySequential
isStrictlySequential,
getValidateMoves :: PGNOptions -> IsStrictlySequential
getValidateMoves = IsStrictlySequential
validateMoves,
getTextEncoding :: PGNOptions -> TextEncoding
getTextEncoding = TextEncoding
textEncoding,
getIdentificationTags :: PGNOptions -> [String]
getIdentificationTags = [String]
identificationTags,
getMinimumPlies :: PGNOptions -> NMoves
getMinimumPlies = NMoves
minimumPlies
} = [(String, ShowS)] -> ShowS
Text.ShowList.showsAssociationList' [
(
String
databaseFilePathTag,
String -> ShowS
forall a. Show a => a -> ShowS
shows String
databaseFilePath
), (
String
isStrictlySequentialTag,
IsStrictlySequential -> ShowS
forall a. Show a => a -> ShowS
shows IsStrictlySequential
isStrictlySequential
), (
String
validateMovesTag,
IsStrictlySequential -> ShowS
forall a. Show a => a -> ShowS
shows IsStrictlySequential
validateMoves
), (
String
Text.Encoding.tag,
TextEncoding -> ShowS
forall a. Show a => a -> ShowS
shows TextEncoding
textEncoding
), (
String -> ShowS
showString String
identificationTagTag String
"s",
[String] -> ShowS
forall a. Show a => a -> ShowS
shows [String]
identificationTags
), (
String
minimumPliesTag,
NMoves -> ShowS
forall a. Show a => a -> ShowS
shows NMoves
minimumPlies
)
]
instance Data.Default.Default PGNOptions where
def :: PGNOptions
def = MkPGNOptions :: String
-> IsStrictlySequential
-> IsStrictlySequential
-> TextEncoding
-> [String]
-> NMoves
-> PGNOptions
MkPGNOptions {
getDatabaseFilePath :: String
getDatabaseFilePath = String
"pgn/bishbosh.pgn",
getIsStrictlySequential :: IsStrictlySequential
getIsStrictlySequential = IsStrictlySequential
True,
getValidateMoves :: IsStrictlySequential
getValidateMoves = IsStrictlySequential
True,
getTextEncoding :: TextEncoding
getTextEncoding = TextEncoding
forall a. Default a => a
Data.Default.def,
getIdentificationTags :: [String]
getIdentificationTags = [String
"ECO", String
"Variation"],
getMinimumPlies :: NMoves
getMinimumPlies = NMoves
1
}
instance HXT.XmlPickler PGNOptions where
xpickle :: PU PGNOptions
xpickle = String -> PU PGNOptions -> PU PGNOptions
forall a. String -> PU a -> PU a
HXT.xpElem String
tag (PU PGNOptions -> PU PGNOptions)
-> (PU
(String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
-> PU PGNOptions)
-> PU
(String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
-> PU PGNOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
-> PGNOptions,
PGNOptions
-> (String, IsStrictlySequential, IsStrictlySequential,
TextEncoding, [String], NMoves))
-> PU
(String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
-> PU PGNOptions
forall a b. (a -> b, b -> a) -> PU a -> PU b
HXT.xpWrap (
\(String
a, IsStrictlySequential
b, IsStrictlySequential
c, TextEncoding
d, [String]
e, NMoves
f) -> String
-> IsStrictlySequential
-> IsStrictlySequential
-> TextEncoding
-> [String]
-> NMoves
-> PGNOptions
mkPGNOptions String
a IsStrictlySequential
b IsStrictlySequential
c TextEncoding
d [String]
e NMoves
f,
\MkPGNOptions {
getDatabaseFilePath :: PGNOptions -> String
getDatabaseFilePath = String
databaseFilePath,
getIsStrictlySequential :: PGNOptions -> IsStrictlySequential
getIsStrictlySequential = IsStrictlySequential
isStrictlySequential,
getValidateMoves :: PGNOptions -> IsStrictlySequential
getValidateMoves = IsStrictlySequential
validateMoves,
getTextEncoding :: PGNOptions -> TextEncoding
getTextEncoding = TextEncoding
textEncoding,
getIdentificationTags :: PGNOptions -> [String]
getIdentificationTags = [String]
identificationTags,
getMinimumPlies :: PGNOptions -> NMoves
getMinimumPlies = NMoves
minimumPlies
} -> (String
databaseFilePath, IsStrictlySequential
isStrictlySequential, IsStrictlySequential
validateMoves, TextEncoding
textEncoding, [String]
identificationTags, NMoves
minimumPlies)
) (PU
(String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
-> PU PGNOptions)
-> PU
(String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
-> PU PGNOptions
forall a b. (a -> b) -> a -> b
$ PU String
-> PU IsStrictlySequential
-> PU IsStrictlySequential
-> PU TextEncoding
-> PU [String]
-> PU NMoves
-> PU
(String, IsStrictlySequential, IsStrictlySequential, TextEncoding,
[String], NMoves)
forall a b c d e f.
PU a
-> PU b -> PU c -> PU d -> PU e -> PU f -> PU (a, b, c, d, e, f)
HXT.xp6Tuple (
String -> PU String
HXT.xpTextAttr String
databaseFilePathTag
) (
PGNOptions -> IsStrictlySequential
getIsStrictlySequential PGNOptions
def IsStrictlySequential
-> PU IsStrictlySequential -> PU IsStrictlySequential
forall a. Eq a => a -> PU a -> PU a
`HXT.xpDefault` String -> PU IsStrictlySequential -> PU IsStrictlySequential
forall a. String -> PU a -> PU a
HXT.xpAttr String
isStrictlySequentialTag PU IsStrictlySequential
forall a. XmlPickler a => PU a
HXT.xpickle
) (
PGNOptions -> IsStrictlySequential
getValidateMoves PGNOptions
def IsStrictlySequential
-> PU IsStrictlySequential -> PU IsStrictlySequential
forall a. Eq a => a -> PU a -> PU a
`HXT.xpDefault` String -> PU IsStrictlySequential -> PU IsStrictlySequential
forall a. String -> PU a -> PU a
HXT.xpAttr String
validateMovesTag PU IsStrictlySequential
forall a. XmlPickler a => PU a
HXT.xpickle
) PU TextEncoding
forall a. XmlPickler a => PU a
HXT.xpickle (
PU String -> PU [String]
forall a. PU a -> PU [a]
HXT.xpList (PU String -> PU [String])
-> (PU String -> PU String) -> PU String -> PU [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> PU String -> PU String
forall a. String -> PU a -> PU a
HXT.xpElem String
identificationTagTag (PU String -> PU [String]) -> PU String -> PU [String]
forall a b. (a -> b) -> a -> b
$ String -> PU String
HXT.xpTextAttr String
"tag"
) (
PGNOptions -> NMoves
getMinimumPlies PGNOptions
def NMoves -> PU NMoves -> PU NMoves
forall a. Eq a => a -> PU a -> PU a
`HXT.xpDefault` String -> PU NMoves -> PU NMoves
forall a. String -> PU a -> PU a
HXT.xpAttr String
minimumPliesTag PU NMoves
forall a. XmlPickler a => PU a
HXT.xpickle
) where
def :: PGNOptions
def = PGNOptions
forall a. Default a => a
Data.Default.def
mkPGNOptions
:: System.FilePath.FilePath
-> ContextualNotation.PGN.IsStrictlySequential
-> ContextualNotation.StandardAlgebraic.ValidateMoves
-> System.IO.TextEncoding
-> [ContextualNotation.PGN.Tag]
-> Component.Move.NMoves
-> PGNOptions
mkPGNOptions :: String
-> IsStrictlySequential
-> IsStrictlySequential
-> TextEncoding
-> [String]
-> NMoves
-> PGNOptions
mkPGNOptions String
databaseFilePath IsStrictlySequential
isStrictlySequential IsStrictlySequential
validateMoves TextEncoding
textEncoding [String]
identificationTags NMoves
minimumPlies
| IsStrictlySequential -> IsStrictlySequential
not (IsStrictlySequential -> IsStrictlySequential)
-> IsStrictlySequential -> IsStrictlySequential
forall a b. (a -> b) -> a -> b
$ String -> IsStrictlySequential
System.FilePath.isValid String
databaseFilePath = Exception -> PGNOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> PGNOptions)
-> (String -> Exception) -> String -> PGNOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkInvalidDatum (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Input.PGNOptions.mkPGNOptions:\tinvalid " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
databaseFilePathTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> PGNOptions) -> String -> PGNOptions
forall a b. (a -> b) -> a -> b
$ String -> ShowS
forall a. Show a => a -> ShowS
shows String
databaseFilePath String
"."
| (String -> IsStrictlySequential)
-> [String] -> IsStrictlySequential
forall (t :: * -> *) a.
Foldable t =>
(a -> IsStrictlySequential) -> t a -> IsStrictlySequential
any String -> IsStrictlySequential
forall (t :: * -> *) a. Foldable t => t a -> IsStrictlySequential
null [String]
identificationTags = Exception -> PGNOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> PGNOptions)
-> (String -> Exception) -> String -> PGNOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkNullDatum (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Input.PGNOptions.mkPGNOptions:\tno " (String -> PGNOptions) -> String -> PGNOptions
forall a b. (a -> b) -> a -> b
$ String -> ShowS
forall a. Show a => a -> ShowS
shows String
identificationTagTag String
" can be null."
| duplicateTags :: [String]
duplicateTags@(String
_ : [String]
_) <- ([String] -> String) -> [[String]] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map [String] -> String
forall a. [a] -> a
head ([[String]] -> [String])
-> ([[String]] -> [[String]]) -> [[String]] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String] -> IsStrictlySequential) -> [[String]] -> [[String]]
forall a. (a -> IsStrictlySequential) -> [a] -> [a]
filter ((NMoves -> NMoves -> IsStrictlySequential
forall a. Eq a => a -> a -> IsStrictlySequential
/= NMoves
1) (NMoves -> IsStrictlySequential)
-> ([String] -> NMoves) -> [String] -> IsStrictlySequential
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> NMoves
forall (t :: * -> *) a. Foldable t => t a -> NMoves
length) ([[String]] -> [String]) -> [[String]] -> [String]
forall a b. (a -> b) -> a -> b
$ [String] -> [[String]]
forall (foldable :: * -> *) a.
(Foldable foldable, Ord a) =>
foldable a -> [[a]]
ToolShed.Data.Foldable.gather [String]
identificationTags
= Exception -> PGNOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> PGNOptions)
-> (String -> Exception) -> String -> PGNOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkDuplicateData (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Input.PGNOptions.mkPGNOptions:\tduplicate " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
identificationTagTag ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
's' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
Text.ShowList.showsAssociation (String -> PGNOptions) -> String -> PGNOptions
forall a b. (a -> b) -> a -> b
$ [String] -> ShowS
forall a. Show a => a -> ShowS
shows [String]
duplicateTags String
"."
| NMoves
minimumPlies NMoves -> NMoves -> IsStrictlySequential
forall a. Ord a => a -> a -> IsStrictlySequential
< NMoves
0 = Exception -> PGNOptions
forall a e. Exception e => e -> a
Control.Exception.throw (Exception -> PGNOptions)
-> (String -> Exception) -> String -> PGNOptions
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Exception
Data.Exception.mkOutOfBounds (String -> Exception) -> ShowS -> String -> Exception
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"BishBosh.Input.PGNOptions.mkPGNOptions:\t" (String -> PGNOptions) -> String -> PGNOptions
forall a b. (a -> b) -> a -> b
$ String -> ShowS
forall a. Show a => a -> ShowS
shows String
minimumPliesTag String
" can't be negative."
| IsStrictlySequential
otherwise = MkPGNOptions :: String
-> IsStrictlySequential
-> IsStrictlySequential
-> TextEncoding
-> [String]
-> NMoves
-> PGNOptions
MkPGNOptions {
getDatabaseFilePath :: String
getDatabaseFilePath = ShowS
System.FilePath.normalise String
databaseFilePath,
getIsStrictlySequential :: IsStrictlySequential
getIsStrictlySequential = IsStrictlySequential
isStrictlySequential,
getValidateMoves :: IsStrictlySequential
getValidateMoves = IsStrictlySequential
validateMoves,
getTextEncoding :: TextEncoding
getTextEncoding = TextEncoding
textEncoding,
getIdentificationTags :: [String]
getIdentificationTags = [String]
identificationTags,
getMinimumPlies :: NMoves
getMinimumPlies = NMoves
minimumPlies
}