@@ -13,33 +13,35 @@
13 Example implementations using Yesod and Happstack are available
13 Example implementations using Yesod and Happstack are available
14 at <https://github.com/tazjin/Elm/tree/master/Examples>
14 at <https://github.com/tazjin/Elm/tree/master/Examples>
16−module Language.Elm (
16+module Language.Elm (compile, toHtml, moduleName, runtime, docs) where
22−import qualified Ast as Ast
23−import qualified Libraries as Libraries
24import Data.List (intercalate)
18import Data.List (intercalate)
25import Data.Version (showVersion)
19import Data.Version (showVersion)
26import CompileToJS (showErr, jsModule)
20import CompileToJS (showErr, jsModule)
27−import ExtractNoscript
28−import GenerateHtml
21+import GenerateHtml (generateHtml)
29−import Initialize
22+import Initialize (buildFromSource)
24+import Parse.Modules (moduleDef)
30import Text.Blaze.Html (Html)
25import Text.Blaze.Html (Html)
26+import Text.Parsec (option,optional)
31import Paths_Elm
27import Paths_Elm
33-- |This function compiles Elm code to JavaScript.
29-- |This function compiles Elm code to JavaScript.
34compile :: String -> String
30compile :: String -> String
35compile source = either showErr jsModule modul
31compile source = either showErr jsModule modul
36− where modul = buildFromSource True source
33+ modul = buildFromSource True source
38-- |This function extracts the module name of a given source program.
35-- |This function extracts the module name of a given source program.
39moduleName :: String -> String
36moduleName :: String -> String
40−moduleName source = either (const "Main") getName modul
37+moduleName source = case iParse getModuleName "" source of
41− where modul = buildFromSource False source
38+ Right name -> name
43+ (names, _) <- option (["Main"],[]) moduleDef
42− getName (Ast.Module names _ _ _) = intercalate "." names
44+ return (intercalate "." names)
44-- |This function compiles Elm code into a full HTML page.
46-- |This function compiles Elm code into a full HTML page.
45toHtml :: String -- ^ Location of elm-min.js as expected by the browser
47toHtml :: String -- ^ Location of elm-min.js as expected by the browser