Skip to content

Commit

Permalink
fix #96 by adding a special case for dictionaries inside tuples
Browse files Browse the repository at this point in the history
This should be investigated further, in case it happens for other nestings. Perhaps the encode function ought to also return the final name of the txt it creates, so that things higher up the tree have access to it.
  • Loading branch information
CSchank committed Jul 15, 2019
1 parent 0ea1d4f commit 6563e88
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Generate/Codec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ generateEncoder l (CustomT name edts) =
encodeEt indt (PairT (et0,n0,d0) (et1,n1,d1), n, _) =
let
indtTxt = T.pack $ show indt
fstName = T.concat ["fst",indtTxt,case et0 of DictT _ _ -> "AsList"; _ -> "","Txt"]
sndName = T.concat ["snd",indtTxt,case et1 of DictT _ _ -> "AsList"; _ -> "","Txt"]
in
indtTxts indt [T.concat[n, "Txt ="]
," let"
,T.concat[" (fst",indtTxt,",snd",indtTxt,") = ",n]] ++
encodeEt (indt+2) (et0,T.concat["fst",indtTxt],d0) ++
encodeEt (indt+2) (et1,T.concat["snd",indtTxt],d1) ++
indtTxts indt [" in"
,T.concat [" tConcat [fst",indtTxt,"Txt,\"",delim,"\",snd",indtTxt,"Txt]"]
,T.concat [" tConcat [",fstName,",\"",delim,"\",",sndName,"]"]
]
encodeEt indt (TripleT (et0,n0,d0) (et1,n1,d1) (et2,n2,d2), n, _) =
let
indtTxt = T.pack $ show indt
fstName = T.concat ["fst",indtTxt,case et0 of DictT _ _ -> "AsList"; _ -> "","Txt"]
sndName = T.concat ["snd",indtTxt,case et1 of DictT _ _ -> "AsList"; _ -> "","Txt"]
thdName = T.concat ["thd",indtTxt,case et2 of DictT _ _ -> "AsList"; _ -> "","Txt"]
in
indtTxts indt $ [T.concat[n, "Txt ="]
," let"
Expand All @@ -63,7 +68,7 @@ generateEncoder l (CustomT name edts) =
,T.unlines $ encodeEt 2 (et1,T.concat["snd",indtTxt],d1)
,T.unlines $ encodeEt 2 (et2,T.concat["thd",indtTxt],d2)
," in"
,T.concat [" tConcat[fst",indtTxt,"Txt,\"",delim,"\",snd",indtTxt,"Txt,\"",delim,"\",thd",indtTxt,"Txt]"]
,T.concat [" tConcat[",fstName,",\"",delim,"\",",sndName,",\"",delim,"\",",thdName,"]"]
]
encodeEt indt (ListT (et, etn, etd), n, _) =
let
Expand Down

0 comments on commit 6563e88

Please sign in to comment.