@@ -1,10 +1,6 @@
1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
2{- | This module exports the functions necessary for compiling Elm code into the
2{- | This module exports the functions necessary for compiling Elm code into the
3− respective HTML, JS and CSS code.
3+ respective HTML, CSS, and JS code.
5− The type class @'ElmSource'@ requires an instance for all types that the Elm
6− compiler understands. The provided instances for String, Text and QuasiQuoted
7− Elm source code should be sufficient.
9 The documentation for the Elm language is available at
5 The documentation for the Elm language is available at
10 <http://elm-lang.org/Documentation.elm>, and many interactive examples are
6 <http://elm-lang.org/Documentation.elm>, and many interactive examples are
@@ -26,21 +22,22 @@ import Text.Blaze.Html (Html)
26import Text.Parsec (option,optional)
22import Text.Parsec (option,optional)
27import Paths_Elm
23import Paths_Elm
29−-- |This function compiles Elm code to JavaScript.
25+-- |This function compiles Elm code to JavaScript. It will return either
26+-- an error message or the compiled JS code.
30−compile :: String -> String
27+compile :: String -> Either String String
31−compile source = either showErr jsModule modul
28+compile source = fmap jsModule modul
33− modul = buildFromSource True source
30+ modul = buildFromSource False source
35-- |This function extracts the module name of a given source program.
32-- |This function extracts the module name of a given source program.
36−moduleName :: String -> String
33+moduleName :: String -> Maybe String
37moduleName source = case iParse getModuleName "" source of
34moduleName source = case iParse getModuleName "" source of
38− Right name -> name
35+ Right name -> Just name
39− Left _ -> "Main"
36+ Left _ -> Nothing
41 getModuleName = do
38 getModuleName = do
42 optional freshLine
39 optional freshLine
43− (names, _) <- option (["Main"],[]) moduleDef
40+ (names, _) <- moduleDef
44 return (intercalate "." names)
41 return (intercalate "." names)
46-- |This function compiles Elm code into a full HTML page.
43-- |This function compiles Elm code into a full HTML page.