-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmdList.hs
41 lines (30 loc) · 1.13 KB
/
CmdList.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
module CmdList ( CmdSpec(..)
,CmdList(..)
,mergeCmdLists
,makeCmdList
,safeCmds
,unsafeCmds
,nsCmdList
,makeNsCmdList
,onlySafe
,onlyUnsafe
,emptyCmdList
) where
import Internal.Types (TclCmd)
data CmdSpec = CmdSpec { cmdSpecName :: String,
cmdSpecCmd :: TclCmd,
cmdSpecSafe :: Bool }
data CmdList = CmdList { unCmdList :: [CmdSpec] }
emptyCmdList = CmdList []
onlySafe (CmdList cl) = CmdList (filter cmdSpecSafe cl)
onlyUnsafe (CmdList cl) = CmdList (filter (not . cmdSpecSafe) cl)
makeCmdList = makeNsCmdList ""
makeNsCmdList :: String -> [(String,TclCmd)] -> CmdList
makeNsCmdList p = CmdList . map (toCmdSpec p)
safeCmds = map (\(n,c) -> (n,c,True))
unsafeCmds = map (\(n,c) -> (n,c,False))
nsCmdList p = CmdList . map (toCmdSpec_ p)
toCmdSpec p (n,v) = CmdSpec (p ++ n) v True
toCmdSpec_ p (n,v,s) = CmdSpec (p ++ n) v s
mergeCmdLists :: [CmdList] -> CmdList
mergeCmdLists = CmdList . concat . map unCmdList