on 29dfd5a help sign in
elk/elm/src/Compiler.hs
44 lines 1.3 kB history raw
1module Main where
3import Data.List (isPrefixOf)
4import CompileToJS
5import GenerateHtml
6import System.Environment
7import Text.Blaze.Html.Renderer.String (renderHtml)
9main = getArgs >>= parse
11parse ("--help":_) = putStrLn usage
12parse ("--version":_) = putStrLn "The Elm Compiler 0.1.1.7"
13parse [loc,file]
14 | "--runtime-location=" `isPrefixOf` loc =
15 produceHtml (tail $ dropWhile (/='=') loc) file
16 | otherwise = putStrLn usageMini
17parse [file] = produceHtml "elm-mini.js" file
18parse _ = putStrLn usageMini
20produceHtml libLoc file = do
21 code <- readFile file
22 let name = takeWhile (/='.') file
23 case compile code of
24 Left err -> putStrLn err
25 Right jsCode -> writeFile (name ++ ".html") . renderHtml $
26 generateHtml libLoc name jsCode
28usageMini =
29 "Usage: elm [OPTIONS] FILE\n\
30 \Try `elm --help' for more information."
32usage =
33 "Usage: elm [OPTIONS] FILE\n\
34 \Compile .elm files to .html files.\n\
35 \Example: elm --runtime-location=../elm-mini.js main.elm\n\
36 \\n\
37 \Resource Locations:\n\
38 \ --runtime-location set the location of the Elm runtime (elm-mini.js)\n\
39 \\n\
40 \Compiler Information:\n\
41 \ --version print the version information and exit\n\
42 \ --help display this help and exit\n\
43 \\n\
44 \Elm home page: <http://elm-lang.org>"