1{-# LANGUAGE DeriveDataTypeable #-}
4import Data.Either (lefts, rights)
5import Data.List (intersect, intercalate)
6import Data.Maybe (fromMaybe)
7import System.Console.CmdArgs
8import Text.Blaze.Html.Renderer.String (renderHtml)
20 , runtime :: Maybe FilePath
23 , import_js :: [FilePath]
25 deriving (Data,Typeable,Show,Eq)
27elm = ELM { make = False &= help "automatically compile dependencies."
28 , files = def &= args &= typ "FILES"
29 , runtime = Nothing &= typFile &=
30 help "Specify a custom location for Elm's runtime system."
31 , separate_js = False &= help "Compile to separate HTML and JS files."
32 , only_js = False &= help "Compile only to JavaScript."
33 , import_js = [] &= typFile &= help "Include a JavaScript file before the body of the Elm program. Can be used many times. Files will be included in the given order."
35 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
36 summary "The Elm Compiler v0.3.5, (c) Evan Czaplicki"
40 mini <- getDataFileName "elm-runtime-0.3.5.js"
43compileArgs mini (ELM _ [] _ _ _ _) =
44 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
45compileArgs mini (ELM make files rtLoc split only js) =
46 mapM_ (fileTo get what js $ fromMaybe mini rtLoc) files
47 where get = if make then getModules [] else getModule
48 what = if only then JS else
49 if split then Split else HTML
51data What = JS | HTML | Split
53fileTo get what jsFiles rtLoc file = do
55 jss <- concat `fmap` mapM readFile jsFiles
57 Left err -> putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
59 let name = reverse . tail . dropWhile (/='.') $ reverse file
61 html = name ++ ".html"
63 JS -> writeFile js $ jss ++ concatMap jsModule ms
64 HTML -> writeFile html . renderHtml $ modulesToHtml "" rtLoc jss ms
66 writeFile html . renderHtml $ linkedHtml rtLoc js ms
67 writeFile js $ jss ++ concatMap jsModule ms
69getModules :: [String] -> FilePath -> IO (Either String [Module])
70getModules uses file = do
72 case initialize code of
73 Left err -> return . Left $ "Error in " ++ file ++ ":\n" ++ err
74 Right modul@(Module _ _ imports _ _) ->
75 let imps = filter (`notElem` builtInModules) $ map fst imports in
76 case intersect uses imps of
77 x:_ -> return . Left $ "Error: Cyclic dependency. Module " ++
78 x ++ " depends on itself."
80 ems <- mapM (getModules (uses ++ imps) . toFilePath) imps
81 return $ case lefts ems of
82 [] -> Right $ concat (rights ems) ++ [modul]
83 errs -> Left $ intercalate "\n" errs
85getModule :: FilePath -> IO (Either String [Module])
88 return . fmap (:[]) $ initialize code
90toFilePath :: String -> FilePath
91toFilePath modul = map (\c -> if c == '.' then '/' else c) modul ++ ".elm"
94 concat [ map ("Data."++) [ "List", "Char", "Maybe" ]
95 , map ("Signal."++) [ "Mouse", "Keyboard.Raw"
96 , "Window", "Time", "HTTP", "Input", "Random" ]
97 , [ "Element", "Text", "Color", "Line" ]
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