Sha256: c4db4def7914ecdc14925f3681b6d7ea173b54f2e0c62de3024984201fa4f9b5
Contents?: true
Size: 889 Bytes
Versions: 3
Compression:
Stored size: 889 Bytes
Contents
{-# LANGUAGE TemplateHaskell #-} module Interpolator where import Language.Haskell.TH import Language.Haskell.TH.Syntax import Language.Haskell.Meta.Parse -- The first string in each pair is literal, the second is a variable to -- be interpolated. parse :: String -> [(String, String)] -- parse "Foo#{foo}rah#{foo}" = [("Foo", "foo ++ bar"), ("rah", "foo")] parse str = gen :: [(String, String)] -> Q Exp -> Q Exp gen [] x = x -- gen ((string,variable) : xs) x = gen xs [| $x ++ $(lift string) ++ $(return $ VarE $ mkName variable) |] gen ((string,expr) : xs) x = gen xs [| $x ++ $(lift string) ++ $(return $ lift $ parseExp expr) |] -- gen ((string,variable) : xs) x = gen xs [| $x ++ $(lift string) ++ $(stringE variable) |] -- Here we generate the Haskell code for the splice -- from an input format string. interpolate :: String -> Q Exp interpolate s = gen (parse s) [| "" |]
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hubris-0.0.6 | Haskell/Language/Ruby/Hubris/Interpolator.hs |
hubris-0.0.5 | Haskell/Language/Ruby/Hubris/Interpolator.hs |
hubris-0.0.4 | Haskell/Language/Ruby/Hubris/Interpolator.hs |