1{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
2{- | This module exports the functions necessary for compiling Elm code into the
3 respective HTML, CSS, and JS code.
5 The documentation for the Elm language is available at
6 <http://elm-lang.org/Documentation.elm>, and many interactive examples are
7 available at <http://elm-lang.org/Examples.elm>
9 Example implementations using Yesod and Happstack are available
10 at <https://github.com/tazjin/Elm/tree/master/Examples>
12module Language.Elm (compile, toHtml, moduleName, runtime, docs) where
14import Data.List (intercalate)
15import Data.Version (showVersion)
16import CompileToJS (showErr, jsModule)
17import GenerateHtml (generateHtml)
18import Initialize (buildFromSource)
20import Parse.Modules (moduleDef)
21import Text.Blaze.Html (Html)
22import Text.Parsec (option,optional)
25-- |This function compiles Elm code to JavaScript. It will return either
26-- an error message or the compiled JS code.
27compile :: String -> Either String String
28compile source = fmap jsModule modul
30 modul = buildFromSource False source
32-- |This function extracts the module name of a given source program.
33moduleName :: String -> Maybe String
34moduleName source = case iParse getModuleName "" source of
35 Right name -> Just name
40 (names, _) <- moduleDef
41 return (intercalate "." names)
43-- |This function compiles Elm code into a full HTML page.
44toHtml :: String -- ^ Location of elm-min.js as expected by the browser
45 -> String -- ^ The page title
46 -> String -- ^ The elm source code
50-- |The absolute path to Elm's runtime system.
52runtime = getDataFileName "elm-runtime.js"
54-- |The absolute path to Elm's core library documentation.
56docs = getDataFileName "docs.json"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list