on master help sign in
Change the Haskell API for compilation to make it easier to see error messages.
1c80966evancz
compiler/Language/Elm.hs+10−13
@@ -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.
4−
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.
8
4
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
28
24
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
32 where
29 where
33− modul = buildFromSource True source
30+ modul = buildFromSource False source
34
31
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
40 where
37 where
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)
45
42
46-- |This function compiles Elm code into a full HTML page.
43-- |This function compiles Elm code into a full HTML page.
compiler/Model/Ast.hs+1
@@ -9,6 +9,7 @@ import qualified Text.Pandoc as Pandoc
9import Data.Data
9import Data.Data
10
10
11data Module = Module [String] Exports Imports [Statement]
11data Module = Module [String] Exports Imports [Statement]
12+ deriving (Show)
12
13
13type Exports = [String]
14type Exports = [String]
14
15