-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTemplates.hs
63 lines (54 loc) · 2.24 KB
/
Templates.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{-# LANGUAGE TemplateHaskell, DeriveLift, ImplicitParams #-}
module Templates where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Graphics.UI.Gtk
import Data.Char
import Control.Monad
import Data.Maybe
import Data.AppSettings
-- castFun :: Type -> ExpQ
-- castFun (ConT n) = varE $ mkName ("castTo" ++ nameBase n)
-- uncamel :: String -> String
-- uncamel (c:c':cs) | isUpper c' = c : '-' : uncamel (toLower c' : cs)
-- uncamel (c:cs) = c : uncamel cs
-- uncamel s = s
-- expandField :: Name -> VarBangType -> Q (Name, Name, Stmt)
-- expandField b (v, _, ty) = do
-- v' <- newName (nameBase v)
-- stmt <- bindS (varP v')
-- (appsE [[|builderGetObject|]
-- ,varE b
-- ,castFun ty
-- ,stringE (uncamel (nameBase v))
-- ])
-- return (v, v', stmt)
-- mkWidgetGetter :: Name -> String -> Q [Dec]
-- mkWidgetGetter name fNameS = reify name >>= \case
-- TyConI (DataD _ _ _ _ [RecC conName fields] _) -> do
-- let fName = mkName fNameS
-- sig <- sigD fName (arrowT `appT` [t|Builder|] `appT` ([t|IO|] `appT` conT name))
-- b <- newName "b"
-- (vs, vs', stmts) <- unzip3 <$> mapM (expandField b) fields
-- f <- funD fName
-- [clause [varP b]
-- (normalB $ doE (map return stmts
-- ++ [noBindS $ appE [|return|] $ return $ RecConE conName (zip vs (map VarE vs'))]))
-- []]
-- return [sig, f]
-- _ -> error "foo"
-- ----------------------------------------------------------------
-- declareSettings :: String -> [(String, TypeQ, ExpQ, ExpQ)] -> Q [Dec]
-- declareSettings x l = do
-- (decs, es) <- unzip <$> mapM f l
-- let n = mkName x
-- xDec <- funD n [clause [] (normalB (listE es)) []]
-- return (join decs ++ [xDec])
-- where
-- f :: (String, TypeQ, ExpQ, ExpQ) -> Q ([Dec], ExpQ)
-- f (s, t, def, fun) = do
-- let n = mkName s
-- sig <- sigD n ([t|Setting|] `appT` t)
-- dec <- funD n [clause [] (normalB ([|Setting|] `appE` stringE (uncamel s) `appE` def)) []]
-- return ([sig, dec], fun `appE` varE n)
-- ----------------------------------------------------------------