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 qualified Data.List as List
15import qualified Data.Map as Map
16import Data.Version (showVersion)
17import Generate.JavaScript (showErr, jsModule)
18import Generate.Html (generateHtml)
19import Initialize (buildFromSource)
21import Parse.Module (moduleDef)
22import SourceSyntax.Module
23import Text.Blaze.Html (Html)
24import Text.Parsec (option,optional)
25import qualified Text.PrettyPrint as P
28-- |This function compiles Elm code to JavaScript. It will return either
29-- an error message or the compiled JS code.
30compile :: String -> Either String String
32 case buildFromSource Map.empty source of
33 Left docs -> Left . unlines $ map P.render docs
34 Right modul -> Right $ jsModule (modul :: MetadataModule () ())
36-- |This function extracts the module name of a given source program.
37moduleName :: String -> Maybe String
38moduleName source = case iParse getModuleName "" source of
39 Right name -> Just name
44 (names, _) <- moduleDef
45 return (List.intercalate "." names)
47-- |This function compiles Elm code into a full HTML page.
48toHtml :: String -- ^ Location of elm-min.js as expected by the browser
49 -> String -- ^ The page title
50 -> String -- ^ The elm source code
54-- |The absolute path to Elm's runtime system.
56runtime = getDataFileName "elm-runtime.js"
58-- |The absolute path to Elm's core library documentation.
60docs = 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