1{-# OPTIONS_GHC -Wall #-}
2module Generate.Substitute (subst) where
4import Control.Arrow (second, (***))
6import AST.Expression.General (Expr'(..), PortImpl(..))
7import qualified AST.Expression.Canonical as Canonical
8import qualified AST.Pattern as Pattern
9import qualified AST.Variable as V
10import Elm.Utils ((|>))
11import qualified Reporting.Annotation as A
14subst :: String -> Canonical.Expr' -> Canonical.Expr' -> Canonical.Expr'
15subst old new expression =
16 let f (A.A a e) = A.A a (subst old new e) in
22 ExplicitList (map f exprs)
25 Binop op (f e1) (f e2)
27 Lambda pattern body ->
28 if Pattern.member old pattern
30 else Lambda pattern (f body)
36 MultiIf (map (f *** f) branches)
41 else Let (map substDef defs) (f body)
43 substDef (Canonical.Definition p e t) =
44 Canonical.Definition p (f e) t
47 map (\(Canonical.Definition p _ _) -> p) defs
48 |> any (Pattern.member old)
50 Var (V.Canonical home x) ->
59 if x == old then new else expression
62 Case (f e) (map substCase cases)
64 substCase (pattern, expr) =
65 if Pattern.member old pattern
67 else (pattern, f expr)
70 Data tag (map f values)
72 Access record field ->
73 Access (f record) field
75 Remove record field ->
76 Remove (f record) field
78 Insert record field value ->
79 Insert (f record) field (f value)
81 Modify record fields ->
82 Modify (f record) (map (second f) fields)
85 Record (map (second f) fields)
100 Out name (f expr) tipe
102 Task name expr tipe ->
103 Task name (f expr) tipe
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