1{-# OPTIONS_GHC -Wall #-}
2module Transform.Substitute (subst) where
4import Control.Arrow (second, (***))
5import SourceSyntax.Expression
6import SourceSyntax.Location
7import qualified Data.Set as Set
8import qualified Transform.SortDefinitions as SD
10subst :: String -> Expr t v -> Expr t v -> Expr t v
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 (SD.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)
28 any (Set.member old . SD.boundVars) [ p | Def p _ <- defs ]
31 TypeAnnotation _ _ -> def
32 Def p e -> Def p (f e)
34 Var x -> if x == old then new else expr
35 Case e cases -> Case (f e) $ map (second f) cases
36 Data name es -> Data name (map f es)
37 Access e x -> Access (f e) x
38 Remove e x -> Remove (f e) x
39 Insert e x v -> Insert (f e) x (f v)
40 Modify r fs -> Modify (f r) (map (second f) fs)
41 Record fs -> Record (map (second f) fs)
43 Markdown uid md es -> Markdown uid md (map f es)
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