1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Canonicalize.Environment
22import qualified Data.Map.Strict as Map
23import qualified Data.Map.Merge.Strict as Map
25import qualified AST.Utils.Binop as Binop
26import qualified AST.Canonical as Can
27import qualified AST.Module.Name as ModuleName
28import qualified Data.Index as Index
29import qualified Data.OneOrMore as OneOrMore
30import qualified Elm.Name as N
31import qualified Reporting.Error.Canonicalize as Error
32import qualified Reporting.Region as R
33import qualified Reporting.Result as Result
41 Result.Result i w Error.Error a
50 { _home :: ModuleName.Canonical
51 , _vars :: Map.Map N.Name Var
52 , _types :: Exposed Type
53 , _ctors :: Exposed Ctor
54 , _binops :: Exposed Binop
55 , _q_vars :: Qualified ForeignVar
56 , _q_types :: Qualified Type
57 , _q_ctors :: Qualified Ctor
62 Map.Map N.Name (OneOrMore.OneOrMore a)
66 Map.Map N.Name (Map.Map N.Name (OneOrMore.OneOrMore a))
76 | Foreign (OneOrMore.OneOrMore ForeignVar)
80 ForeignVar ModuleName.Canonical Can.Annotation
88 = Alias Int ModuleName.Canonical [N.Name] Can.Type
89 | Union Int ModuleName.Canonical
97 = RecordCtor ModuleName.Canonical [N.Name] Can.Type
99 { _c_home :: ModuleName.Canonical
101 , _c_union :: Can.Union
102 , _c_index :: Index.ZeroBased
103 , _c_args :: [Can.Type]
114 , _op_home :: ModuleName.Canonical
116 , _op_annotation :: Can.Annotation
117 , _op_associativity :: Binop.Associativity
118 , _op_precedence :: Binop.Precedence
123-- VARIABLE -- ADD LOCALS
126addLocals :: Map.Map N.Name R.Region -> Env -> Result i w Env
127addLocals names (Env home vars ts cs bs qvs qts qcs) =
130 (Map.mapMissing addLocalLeft)
131 (Map.mapMissing (\_ homes -> homes))
132 (Map.zipWithAMatched addLocalBoth)
136 Result.ok (Env home newVars ts cs bs qvs qts qcs)
139addLocalLeft :: N.Name -> R.Region -> Var
140addLocalLeft _ region =
144addLocalBoth :: N.Name -> R.Region -> Var -> Result i w Var
145addLocalBoth name region var =
148 Result.ok (Local region)
150 Local parentRegion ->
151 Result.throw (Error.Shadowing name parentRegion region)
153 TopLevel parentRegion ->
154 Result.throw (Error.Shadowing name parentRegion region)
161findType :: R.Region -> Env -> N.Name -> Result i w Type
162findType region (Env _ _ types _ _ _ _ _) name =
163 case Map.lookup name types of
164 Just (OneOrMore.One tipe) ->
168 error "TODO findType ambiguous unqualified"
171 error "TODO findType not found" region
174findTypeQual :: R.Region -> Env -> N.Name -> N.Name -> Result i w Type
175findTypeQual region (Env _ _ _ _ _ _ types _) prefix name =
176 case Map.lookup prefix types of
178 case Map.lookup name qualified of
179 Just (OneOrMore.One tipe) ->
183 error "TODO findTypeQual ambiguous qualified" more
186 error "TODO findTypeQual no qualified"
189 error "TODO findTypeQual not found" region
196findCtor :: R.Region -> Env -> N.Name -> Result i w Ctor
197findCtor region (Env _ _ _ ctors _ _ _ _) name =
198 case Map.lookup name ctors of
199 Just (OneOrMore.One ctor) ->
203 error "TODO findCtor ambiguous unqualified"
206 error "TODO findCtor not found" region
209findCtorQual :: R.Region -> Env -> N.Name -> N.Name -> Result i w Ctor
210findCtorQual region (Env _ _ _ _ _ _ _ ctors) prefix name =
211 case Map.lookup prefix ctors of
213 case Map.lookup name qualified of
214 Just (OneOrMore.One pattern) ->
218 error "TODO findCtorQual ambiguous qualified"
221 error "TODO findCtorQual no qualified"
224 error "TODO findCtorQual not found" region
231findBinop :: R.Region -> Env -> N.Name -> Result i w Binop
232findBinop region (Env _ _ _ _ binops _ _ _) name =
233 case Map.lookup name binops of
234 Just (OneOrMore.One binop) ->
238 Result.throw (error "TODO unknown binop" region)
241 Result.throw (error "TODO ambiguous binop" region)
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