module Language.Drasil.Code.DataDesc where
import Language.Drasil.Chunk.Code (CodeVarChunk)
import Data.List (nub)
import Data.List.NonEmpty (NonEmpty(..), fromList)
type DataItem = CodeVarChunk
data DataDesc' = DD Data' Delimiter DataDesc' | End Data'
data Data' = Datum DataItem'
| Data
(NonEmpty DataItem')
Integer
Delimiter
| Junk
data DataItem' = DI
CodeVarChunk
[Delimiter]
type Delimiter = String
dataDesc :: [Data'] -> Delimiter -> DataDesc'
dataDesc :: [Data'] -> Delimiter -> DataDesc'
dataDesc [Data'
d] Delimiter
_ = Data' -> DataDesc'
End Data'
d
dataDesc (Data'
d:[Data']
ds) Delimiter
dlm = Data' -> Delimiter -> DataDesc' -> DataDesc'
DD Data'
d Delimiter
dlm ([Data'] -> Delimiter -> DataDesc'
dataDesc [Data']
ds Delimiter
dlm)
dataDesc [] Delimiter
_ = forall a. HasCallStack => Delimiter -> a
error Delimiter
"DataDesc must have at least one data item"
singleton' :: CodeVarChunk -> Data'
singleton' :: DataItem -> Data'
singleton' DataItem
d = DataItem' -> Data'
Datum forall a b. (a -> b) -> a -> b
$ DataItem -> [Delimiter] -> DataItem'
DI DataItem
d []
list :: CodeVarChunk -> [Delimiter] -> Data'
list :: DataItem -> [Delimiter] -> Data'
list DataItem
d [Delimiter]
dlms = DataItem' -> Data'
Datum forall a b. (a -> b) -> a -> b
$ DataItem -> [Delimiter] -> DataItem'
DI DataItem
d [Delimiter]
dlms
interwovenLists :: [DataItem'] -> Integer -> Delimiter -> Data'
interwovenLists :: [DataItem'] -> Integer -> Delimiter -> Data'
interwovenLists [] Integer
_ Delimiter
_ = forall a. HasCallStack => Delimiter -> a
error Delimiter
"interwovenLists must be passed a non-empty list"
interwovenLists [DataItem']
ds Integer
i Delimiter
dl = NonEmpty DataItem' -> Integer -> Delimiter -> Data'
Data (forall a. [a] -> NonEmpty a
fromList [DataItem']
ds) Integer
i Delimiter
dl
junk :: Data'
junk :: Data'
junk = Data'
Junk
type DataDesc = [Data]
type Delim = Char
data Data = Singleton DataItem
| JunkData
| Line LinePattern Delim
| Lines LinePattern (Maybe Integer) Delim
data LinePattern = Straight [DataItem]
| Repeat [DataItem]
singleton :: DataItem -> Data
singleton :: DataItem -> Data
singleton = DataItem -> Data
Singleton
junkLine :: Data
junkLine :: Data
junkLine = Data
JunkData
singleLine :: LinePattern -> Delim -> Data
singleLine :: LinePattern -> Delim -> Data
singleLine = LinePattern -> Delim -> Data
Line
multiLine :: LinePattern -> Delim -> Data
multiLine :: LinePattern -> Delim -> Data
multiLine LinePattern
l = LinePattern -> Maybe Integer -> Delim -> Data
Lines LinePattern
l forall a. Maybe a
Nothing
multiLine' :: LinePattern -> Integer -> Delim -> Data
multiLine' :: LinePattern -> Integer -> Delim -> Data
multiLine' LinePattern
l Integer
i = LinePattern -> Maybe Integer -> Delim -> Data
Lines LinePattern
l (forall a. a -> Maybe a
Just Integer
i)
straight :: [DataItem] -> LinePattern
straight :: [DataItem] -> LinePattern
straight = [DataItem] -> LinePattern
Straight
repeated :: [DataItem] -> LinePattern
repeated :: [DataItem] -> LinePattern
repeated = [DataItem] -> LinePattern
Repeat
isJunk :: Data -> Bool
isJunk :: Data -> Bool
isJunk Data
JunkData = Bool
True
isJunk Data
_ = Bool
False
isLine :: Data -> Bool
isLine :: Data -> Bool
isLine Line{} = Bool
True
isLine Data
_ = Bool
False
isLines :: Data -> Bool
isLines :: Data -> Bool
isLines Lines{} = Bool
True
isLines Data
_ = Bool
False
getInputs :: DataDesc -> [DataItem]
getInputs :: DataDesc -> [DataItem]
getInputs DataDesc
d = forall a. Eq a => [a] -> [a]
nub forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Data -> [DataItem]
getDataInputs DataDesc
d
getDataInputs :: Data -> [DataItem]
getDataInputs :: Data -> [DataItem]
getDataInputs (Singleton DataItem
v) = [DataItem
v]
getDataInputs (Line LinePattern
lp Delim
_) = LinePattern -> [DataItem]
getPatternInputs LinePattern
lp
getDataInputs (Lines LinePattern
lp Maybe Integer
_ Delim
_) = LinePattern -> [DataItem]
getPatternInputs LinePattern
lp
getDataInputs Data
JunkData = []
getPatternInputs :: LinePattern -> [DataItem]
getPatternInputs :: LinePattern -> [DataItem]
getPatternInputs (Straight [DataItem]
vs) = [DataItem]
vs
getPatternInputs (Repeat [DataItem]
vs) = [DataItem]
vs