2013-09-28 19:39:52 +00:00
|
|
|
{- | This module exports the functions necessary for compiling Elm to JS,
|
|
|
|
and some utilities for making it easier to find some Elm-related files.
|
2012-05-28 16:33:15 +00:00
|
|
|
|
2013-03-11 01:52:16 +00:00
|
|
|
The documentation for the Elm language is available at
|
|
|
|
<http://elm-lang.org/Documentation.elm>, and many interactive examples are
|
|
|
|
available at <http://elm-lang.org/Examples.elm>
|
2012-05-28 16:02:02 +00:00
|
|
|
-}
|
2013-09-11 02:22:33 +00:00
|
|
|
module Language.Elm (compile, moduleName, runtime, docs) where
|
2013-05-28 13:47:57 +00:00
|
|
|
|
2013-07-21 04:08:08 +00:00
|
|
|
import qualified Data.List as List
|
|
|
|
import qualified Data.Map as Map
|
2012-10-03 07:17:09 +00:00
|
|
|
import Data.Version (showVersion)
|
2013-08-06 20:40:54 +00:00
|
|
|
import Generate.JavaScript (jsModule)
|
2013-05-28 13:47:57 +00:00
|
|
|
import Initialize (buildFromSource)
|
2013-08-07 04:20:08 +00:00
|
|
|
import Parse.Module (getModuleName)
|
2013-06-15 02:23:58 +00:00
|
|
|
import SourceSyntax.Module
|
2012-05-29 18:25:43 +00:00
|
|
|
import Text.Blaze.Html (Html)
|
2013-07-16 19:42:37 +00:00
|
|
|
import qualified Text.PrettyPrint as P
|
2013-07-31 16:31:48 +00:00
|
|
|
import qualified Metadata.Prelude as Prelude
|
2012-10-03 06:47:46 +00:00
|
|
|
import Paths_Elm
|
2012-05-29 19:48:24 +00:00
|
|
|
|
2013-06-06 23:11:23 +00:00
|
|
|
-- |This function compiles Elm code to JavaScript. It will return either
|
|
|
|
-- an error message or the compiled JS code.
|
|
|
|
compile :: String -> Either String String
|
2013-07-16 19:42:37 +00:00
|
|
|
compile source =
|
2013-07-31 16:31:48 +00:00
|
|
|
case buildFromSource False Prelude.interfaces source of
|
2013-08-03 19:02:59 +00:00
|
|
|
Left docs -> Left . unlines . List.intersperse "" $ map P.render docs
|
2013-07-16 19:42:37 +00:00
|
|
|
Right modul -> Right $ jsModule (modul :: MetadataModule () ())
|
2013-03-21 09:29:23 +00:00
|
|
|
|
2013-04-04 17:37:43 +00:00
|
|
|
-- |This function extracts the module name of a given source program.
|
2013-06-06 23:11:23 +00:00
|
|
|
moduleName :: String -> Maybe String
|
2013-08-07 04:20:08 +00:00
|
|
|
moduleName = getModuleName
|
2013-04-04 17:37:43 +00:00
|
|
|
|
2012-10-03 19:31:38 +00:00
|
|
|
-- |The absolute path to Elm's runtime system.
|
2013-04-04 17:37:43 +00:00
|
|
|
runtime :: IO FilePath
|
|
|
|
runtime = getDataFileName "elm-runtime.js"
|
|
|
|
|
|
|
|
-- |The absolute path to Elm's core library documentation.
|
|
|
|
docs :: IO FilePath
|
|
|
|
docs = getDataFileName "docs.json"
|