on master help sign in
Change the Haskell API for compilation to make it easier to see error messages.
commit1c80966ace3e6ae29f2f13d86264a163659c433c authorevancz <info@elm-lang.org> dateThu 6 Jun 2013, 16:11 (13 years ago) parent44fecef
2 files changed+11−13
compiler/Language/Elm.hs+10−13 compiler/Model/Ast.hs+1
compiler/Language/Elm.hs+10−13
@@ -1,10 +1,6 @@
11{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
22{- | This module exports the functions necessary for compiling Elm code into the
3− respective HTML, JS and CSS 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.
3+ respective HTML, CSS, and JS code.
84
95 The documentation for the Elm language is available at
106 <http://elm-lang.org/Documentation.elm>, and many interactive examples are
@@ -26,21 +22,22 @@ import Text.Blaze.Html (Html)
2622import Text.Parsec (option,optional)
2723import Paths_Elm
2824
29−-- |This function compiles Elm code to JavaScript.
30−compile :: String -> String
31−compile source = either showErr jsModule modul
25+-- |This function compiles Elm code to JavaScript. It will return either
26+-- an error message or the compiled JS code.
27+compile :: String -> Either String String
28+compile source = fmap jsModule modul
3229 where
33− modul = buildFromSource True source
30+ modul = buildFromSource False source
3431
3532-- |This function extracts the module name of a given source program.
36−moduleName :: String -> String
33+moduleName :: String -> Maybe String
3734moduleName source = case iParse getModuleName "" source of
38− Right name -> name
39− Left _ -> "Main"
35+ Right name -> Just name
36+ Left _ -> Nothing
4037 where
4138 getModuleName = do
4239 optional freshLine
43− (names, _) <- option (["Main"],[]) moduleDef
40+ (names, _) <- moduleDef
4441 return (intercalate "." names)
4542
4643-- |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
99import Data.Data
1010
1111data Module = Module [String] Exports Imports [Statement]
12+ deriving (Show)
1213
1314type Exports = [String]
1415