1{-# OPTIONS_GHC -Wall #-}
2module Transform.Substitute (subst) where
4import Control.Arrow (second, (***))
5import qualified Data.Set as Set
8import AST.Expression.General (Expr'(..))
9import qualified AST.Expression.Canonical as Canonical
10import qualified AST.Pattern as Pattern
11import qualified AST.Variable as V
13subst :: String -> Canonical.Expr' -> Canonical.Expr' -> Canonical.Expr'
15 let f (A a e) = A a (subst old new e) in
17 Range e1 e2 -> Range (f e1) (f e2)
18 ExplicitList es -> ExplicitList (map f es)
19 Binop op e1 e2 -> Binop op (f e1) (f e2)
21 | Set.member old (Pattern.boundVars p) -> expr
22 | otherwise -> Lambda p (f e)
23 App e1 e2 -> App (f e1) (f e2)
24 MultiIf ps -> MultiIf (map (f *** f) ps)
28 | otherwise -> Let (map substDef defs) (f body)
30 substDef (Canonical.Definition p e t) = Canonical.Definition p (f e) t
32 any (Set.member old . Pattern.boundVars) [ p | Canonical.Definition p _ _ <- defs ]
34 Var (V.Canonical home x) ->
38 V.Local -> if x == old then new else expr
40 Case e cases -> Case (f e) $ map (second f) cases
41 Data name es -> Data name (map f es)
42 Access e x -> Access (f e) x
43 Remove e x -> Remove (f e) x
44 Insert e x v -> Insert (f e) x (f v)
45 Modify r fs -> Modify (f r) (map (second f) fs)
46 Record fs -> Record (map (second f) fs)
48 Markdown uid md es -> Markdown uid md (map f es)
49 GLShader _ _ _ -> expr
50 PortIn name st -> PortIn name st
51 PortOut name st signal -> PortOut name st (f signal)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list