1{-# OPTIONS_GHC -Wall #-}
2module Transform.Substitute (subst) where
4import Control.Arrow (second, (***))
5import SourceSyntax.Expression
6import SourceSyntax.Location
7import qualified SourceSyntax.Pattern as Pattern
8import qualified Data.Set as Set
10subst :: String -> Expr -> Expr -> Expr
12 let f (L s e) = L s (subst old new e) in
14 Range e1 e2 -> Range (f e1) (f e2)
15 ExplicitList es -> ExplicitList (map f es)
16 Binop op e1 e2 -> Binop op (f e1) (f e2)
18 | Set.member old (Pattern.boundVars p) -> expr
19 | otherwise -> Lambda p (f e)
20 App e1 e2 -> App (f e1) (f e2)
21 MultiIf ps -> MultiIf (map (f *** f) ps)
25 | otherwise -> Let (map substDef defs) (f body)
27 substDef (Definition p e t) = Definition p (f e) t
29 any (Set.member old . Pattern.boundVars) [ p | Definition p _ _ <- defs ]
31 Var x -> if x == old then new else expr
32 Case e cases -> Case (f e) $ map (second f) cases
33 Data name es -> Data name (map f es)
34 Access e x -> Access (f e) x
35 Remove e x -> Remove (f e) x
36 Insert e x v -> Insert (f e) x (f v)
37 Modify r fs -> Modify (f r) (map (second f) fs)
38 Record fs -> Record (map (second f) fs)
40 Markdown uid md es -> Markdown uid md (map f es)
41 PortIn name st -> PortIn name st
42 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