on a993a19 help sign in
elk/src/Compile.hs
64 lines 1.9 kB history raw
1module Compile (compile) where
3import qualified Data.Map as Map
5import qualified AST.Module as Module
6import qualified Canonicalize
7import Elm.Utils ((|>))
8import qualified Nitpick.PatternMatches as Nitpick
9import qualified Nitpick.TopLevelTypes as Nitpick
10import qualified Parse.Helpers as Parse
11import qualified Parse.Parse as Parse
12import qualified Reporting.Error as Error
13import qualified Reporting.Result as Result
14import qualified Reporting.Warning as Warning
15import qualified Type.Inference as TI
18compile
19 :: String
20 -> String
21 -> Bool
22 -> Module.Interfaces
23 -> String
24 -> Result.Result Warning.Warning Error.Error Module.CanonicalModule
26compile user projectName isRoot interfaces source =
27 do
28 -- determine if default imports should be added
29 -- only elm-lang/core is exempt
30 let needsDefaults =
31 not (user == "elm-lang" && projectName == "core")
33 -- Parse the source code
34 validModule <-
35 Result.mapError Error.Syntax $
36 Parse.program needsDefaults isRoot (getOpTable interfaces) source
38 -- Canonicalize all variables, pinning down where they came from.
39 canonicalModule <-
40 Canonicalize.module' interfaces validModule
42 -- Run type inference on the program.
43 types <-
44 Result.from Error.Type $
45 TI.infer interfaces canonicalModule
47 -- One last round of checks
48 Result.mapError Error.Type $
49 Nitpick.topLevelTypes types (Module.body validModule)
51 Nitpick.patternMatches interfaces canonicalModule
53 -- Add the real list of types
54 let body = (Module.body canonicalModule) { Module.types = types }
56 return $ canonicalModule { Module.body = body }
59getOpTable :: Module.Interfaces -> Parse.OpTable
60getOpTable interfaces =
61 Map.elems interfaces
62 |> concatMap Module.iFixities
63 |> map (\(assoc,lvl,op) -> (op,(lvl,assoc)))
64 |> Map.fromList