on 8a7136a help sign in
elk/elm/src/Compiler.hs
49 lines 1.4 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 :: IO ()
10main = getArgs >>= parse
12parse :: [String] -> IO ()
13parse ("--help":_) = putStrLn usage
14parse ("--version":_) = putStrLn "The Elm Compiler 0.1.2"
15parse [loc,file]
16 | "--runtime-location=" `isPrefixOf` loc =
17 produceHtml (tail $ dropWhile (/='=') loc) file
18 | otherwise = putStrLn usageMini
19parse [file] = produceHtml "elm-mini.js" file
20parse _ = putStrLn usageMini
22produceHtml :: String -> FilePath -> IO ()
23produceHtml libLoc file = do
24 code <- readFile file
25 let name = takeWhile (/='.') file
26 case compile code of
27 Left err -> putStrLn err
28 Right jsCode -> writeFile (name ++ ".html") . renderHtml $
29 generateHtml libLoc name jsCode
31usageMini :: String
32usageMini =
33 "Usage: elm [OPTIONS] FILE\n\
34 \Try `elm --help' for more information."
36usage :: String
37usage =
38 "Usage: elm [OPTIONS] FILE\n\
39 \Compile .elm files to .html files.\n\
40 \Example: elm --runtime-location=../elm-mini.js main.elm\n\
41 \\n\
42 \Resource Locations:\n\
43 \ --runtime-location set the location of the Elm runtime (elm-mini.js)\n\
44 \\n\
45 \Compiler Information:\n\
46 \ --version print the version information and exit\n\
47 \ --help display this help and exit\n\
48 \\n\
49 \Elm home page: <http://elm-lang.org>"