add plain fromString interpolation [for FilePath]

This commit is contained in:
Rhiannon Morris 2020-07-15 11:32:48 +02:00
parent b4a939f364
commit acc476d8a3

View file

@ -17,6 +17,7 @@ data ChunkType = Lit | Var VarType deriving Show
data VarType =
Plain
| FromText
| FromString
| Show
| Reindent !Int
| ReindentList !Int
@ -66,6 +67,11 @@ chunks = reverse . go "" [] . trimEnd where
go "" ((Var FromText, var) : lit acc : cs) rest2
where (var, rest2) = splitVar rest
-- $@var: expands to (fromString $var)
go acc cs ('$' :. '@' :. rest) =
go "" ((Var FromString, var) : lit acc : cs) rest2
where (var, rest2) = splitVar rest
-- $^var: expands to (fromString (show $var))
go acc cs ('$' :. '^' :. rest) =
go "" ((Var Show, var) : lit acc : cs) rest2
@ -119,6 +125,7 @@ chunksToExpQ cs = [|$expr :: Builder|] where
chunk1 (Var t, name) = case t of
Plain -> var
FromText -> [|fromText $var|]
FromString -> [|fromString $var|]
Show -> [|fromString $ show $var|]
Reindent n -> [|reindent n $var|]
ReindentList n -> [|reindentList n $var|]