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-- , verbose_js :: Bool
25 deriving (Data,Typeable,Show,Eq)
27elm = ELM { make = False &= help "automatically compile dependencies."
28 , files = def &= args &= typ "FILES"
29 , runtime = Nothing &= typ "FILE" &=
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-- , verbose_js = False &= help "Produce JavaScript that may be easier to debug."
35 help "Compile Elm programs to HTML, CSS, and JavaScript." &=
36 summary "The Elm Compiler v0.3.0, (c) Evan Czaplicki"
40 mini <- getDataFileName "elm-runtime-0.3.0.js"
43compileArgs mini (ELM _ [] _ _ _) =
44 putStrLn "Usage: elm [OPTIONS] [FILES]\nFor more help: elm --help"
45compileArgs mini (ELM make files rtLoc split only) =
46 mapM_ (fileTo get what $ 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 rtLoc file = do
56 Left err -> putStrLn $ "Error while compiling " ++ file ++ ":\n" ++ err
58 let name = reverse . tail . dropWhile (/='.') $ reverse file
60 html = name ++ ".html"
62 JS -> writeFile js $ concatMap jsModule ms
63 HTML -> writeFile html . renderHtml $ modulesToHtml rtLoc ms
65 writeFile html . renderHtml $ linkedHtml rtLoc js ms
66 writeFile js $ concatMap jsModule ms
68getModules :: [String] -> FilePath -> IO (Either String [Module])
69getModules uses file = do
71 case initialize code of
72 Left err -> return . Left $ "Error in " ++ file ++ ":\n" ++ err
73 Right modul@(Module _ _ imports _) ->
74 let imps = filter (`notElem` builtInModules) $ map fst imports in
75 case intersect uses imps of
76 x:_ -> return . Left $ "Error: Cyclic dependency. Module " ++
77 x ++ " depends on itself."
79 ems <- mapM (getModules (uses ++ imps) . toFilePath) imps
80 return $ case lefts ems of
81 [] -> Right $ concat (rights ems) ++ [modul]
82 errs -> Left $ intercalate "\n" errs
84getModule :: FilePath -> IO (Either String [Module])
87 return . fmap (:[]) $ initialize code
89toFilePath :: String -> FilePath
90toFilePath modul = map (\c -> if c == '.' then '/' else c) modul ++ ".elm"
93 concat [ map ("Data."++) [ "List", "Char", "Maybe" ]
94 , map ("Signal."++) [ "Mouse", "Keyboard.Raw"
95 , "Window", "Time", "HTTP", "Input", "Random" ]
96 , [ "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