on master help sign in
Prepare for second release.

Add a Haskell library so that Elm code can be compiled directly in Haskell. Clean up file names and fix up dependencies.

commit8215dacbab2b314ef8d177fe082b94c3844c219d authorevancz <info@elm-lang.org> dateTue 22 May 2012, 23:45 (14 years ago) parente33d329
6 files changed+36−31
Elm.cabal+18−10 src/Elm.hs → src/Compiler.hs+1−1 src/Initialize.hs−2 src/Language/Elm.hs+10 src/Server.hs+7−4 src/ToHtml.hs−14
Elm.cabal+18−10
@@ -1,6 +1,6 @@
11
22Name: Elm
3−Version: 0.1.0
3+Version: 0.1.1.2
44Synopsis: The Elm compiler and server.
55Description: Elm aims to make client-side web-development more pleasant.
66 It is a statically/strongly typed, functional reactive
@@ -16,7 +16,7 @@ Author: Evan Czaplicki
1616Maintainer: info@elm-lang.org
1717Copyright: Copyright: (c) 2011-2012 Evan Czaplicki
1818
19−Category: Compiler
19+Category: Compiler, Language
2020
2121Build-type: Simple
2222
@@ -29,12 +29,12 @@ source-repository head
2929
3030Executable elm
3131 -- .hs or .lhs file containing the Main module.
32− Main-is: Elm.hs
33− Hs-Source-Dirs: src, src/Parse, src/Types
34− other-modules: Ast, CompileToJS, FreeVar, GenerateHtml, Initialize,
35− Rename, Replace, ToHtml, Binop, Combinators, Lexer,
32+ Main-is: Compiler.hs
33+ Hs-Source-Dirs: src, src/Parse, src/Types, src/Language
34+ other-modules: Ast, CompileToJS, GenerateHtml, Guid, Initialize,
35+ Rename, Language.Elm, Binop, Combinators, Lexer,
3636 ParsePatterns, Parser, ParserLib, ParseTypes, Tokens,
37− Types
37+ Types, Constrain, Hints, Types, Unify
3838
3939 -- Packages needed in order to build this package.
4040 ghc-options: -O3 -rtsopts -auto-all -caf-all
@@ -52,11 +52,19 @@ Executable elm
5252Executable elm-server
5353 Main-is: Server.hs
5454 Hs-Source-Dirs: src, src/Parse, src/Types
55− other-modules: Ast, CompileToJS, FreeVar, GenerateHtml, Initialize,
56− Rename, Replace, ToHtml, Binop, Combinators, Lexer,
55+ other-modules: Ast, CompileToJS, GenerateHtml, Guid, Initialize,
56+ Rename, Language.Elm, Binop, Combinators, Lexer,
5757 ParsePatterns, Parser, ParserLib, ParseTypes, Tokens,
58− Types
58+ Types, Constrain, Hints, Types, Unify
5959 ghc-options: -O3 -rtsopts -auto-all -caf-all
6060 Build-depends: base >=4.2 && <5, containers >= 0.3, transformers >= 0.2,
6161 mtl >= 2, parsec >= 3.1.1, blaze-html == 0.5.0.*,
6262 HTTP >= 4000, happstack-server == 7.0.2
63+
64+Library
65+ exposed-modules: Language.Elm
66+ Hs-Source-Dirs: src, src/Parse, src/Types
67+ other-modules: Ast, CompileToJS, GenerateHtml, Guid, Initialize,
68+ Rename, Binop, Combinators, Lexer,
69+ ParsePatterns, Parser, ParserLib, ParseTypes, Tokens,
70+ Types, Constrain, Hints, Types, Unify
src/Elm.hs → src/Compiler.hsrenamed+1−1
@@ -10,7 +10,7 @@ import Text.Blaze.Html.Renderer.String (renderHtml)
1010main = getArgs >>= parse
1111
1212parse ("--help":_) = putStrLn usage
13−parse ("--version":_) = putStrLn "The Elm Compiler 0.1.0"
13+parse ("--version":_) = putStrLn "The Elm Compiler 0.1.1.1"
1414parse [loc,file]
1515 | "--runtime-location=" `isPrefixOf` loc =
1616 produceHtml (tail $ dropWhile (/='=') loc) file
src/Initialize.hs−2
@@ -6,11 +6,9 @@ import Control.Monad
66import Data.Char (isAlpha)
77import Data.Maybe (mapMaybe)
88import Data.Either (rights)
9−import FreeVar
109import Lexer
1110import Parser (toExpr,toDefs)
1211import Rename (rename)
13−import Replace
1412
1513import Unify
1614import Hints
src/Language/Elm.hsnew file+10
@@ -0,0 +1,10 @@
1+
2+module Language.Elm where
3+
4+import CompileToJS
5+import GenerateHtml
6+import Text.Blaze.Html (Html)
7+
8+compileToHtml :: String -> String -> String -> Html
9+compileToHtml libLoc fileName source =
10+ generateHtml libLoc fileName (compileToJS source)
src/Server.hs+7−4
@@ -7,28 +7,31 @@ import Data.List (isPrefixOf, isSuffixOf)
77import Happstack.Server
88import Happstack.Server.Compression
99import System.Environment
10−import ToHtml
10+import Language.Elm
1111
1212serve :: String -> IO ()
1313serve libLoc = do
14− putStrLn "Elm Server 0.1.0: running at <http://localhost:8000>"
14+ putStrLn "Elm Server 0.1.1.1: running at <http://localhost:8000>"
1515 simpleHTTP nullConf $ do
1616 compressedResponseFilter
1717 msum [ uriRest (serveElm libLoc)
1818 , serveDirectory EnableBrowsing [] "."
1919 ]
2020
21+pageTitle fp =
22+ reverse . takeWhile (/='/') . drop 1 . dropWhile (/='.') $ reverse fp
23+
2124serveElm libLoc fp = do
2225 let ('/':path) = fp
2326 guard (".elm" `isSuffixOf` path)
2427 content <- liftIO (readFile path)
25− ok . toResponse $ compileToHtml libLoc path content
28+ ok . toResponse $ compileToHtml libLoc (pageTitle path) content
2629
2730
2831main = getArgs >>= parse
2932
3033parse ("--help":_) = putStrLn usage
31−parse ("--version":_) = putStrLn "The Elm Server 0.1.0"
34+parse ("--version":_) = putStrLn "The Elm Server 0.1.1.1"
3235parse [] = serve "/elm-mini.js"
3336parse [arg]
3437 | "--runtime-location=" `isPrefixOf` arg =
src/ToHtml.hsdeleted−14
@@ -1,14 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−module ToHtml (compileToHtml) where
3−
4−import CompileToJS
5−import GenerateHtml
6−import qualified Text.Blaze.Html5 as H
7−import qualified Text.Blaze.Html5.Attributes as A
8−
9−pageTitle fp =
10− reverse . takeWhile (/='/') . drop 1 . dropWhile (/='.') $ reverse fp
11−
12−compileToHtml :: String -> String -> String -> H.Html
13−compileToHtml libLoc fileName source =
14− generateHtml libLoc (pageTitle fileName) (compileToJS source)