1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE FlexibleContexts #-}
3module Elm.Compiler (version, parseDependencies, compile, runtimePath) where
5import Control.Monad.Error (MonadError, throwError)
6import qualified Data.List as List
7import qualified Data.Map as Map
8import qualified Text.PrettyPrint as P
10import qualified AST.Module as Module (HeaderAndImports(HeaderAndImports), toInterface)
11import qualified Build.Source as Source
12import qualified Elm.Compiler.Module as PublicModule
13import qualified Elm.Compiler.Version as Version
14import qualified Elm.Utils as Utils
15import qualified Generate.JavaScript as JS
16import qualified Parse.Helpers as Help
17import qualified Parse.Module as Parse
18import qualified Paths_elm_compiler as Compiler
31 :: (MonadError String m)
33 -> m (PublicModule.Name, [PublicModule.Name])
34parseDependencies src =
35 case Help.iParse Parse.headerAndImports src of
39 Right (Module.HeaderAndImports names _exports imports) ->
41 ( PublicModule.Name names
42 , map (PublicModule.Name . fst) imports
48{-| Compiles Elm source code to JavaScript. -}
51 -> Map.Map PublicModule.Name PublicModule.Interface
52 -> Either String (PublicModule.Interface, String)
53compile source interfaces =
54 case Source.build False unwrappedInterfaces source of
55 Left docs -> Left . unlines . List.intersperse "" $ map P.render docs
56 Right modul -> Right (Module.toInterface modul, JS.generate modul)
59 Map.mapKeysMonotonic (\(PublicModule.Name name) -> name) interfaces
64{-| Path to the runtime.
66runtimePath :: IO FilePath
68 Utils.getAsset "compiler" Compiler.getDataFileName "runtime/core.js"
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