gdritter repos telml / a83ad14
cmdline interface improvements Getty Ritter 1 year, 11 months ago
2 changed file(s) with 16 addition(s) and 10 deletion(s). Collapse all Expand all
1212 import qualified HsLua.Core as Lua
1313 import qualified System.Console.GetOpt as Opt
1414 import qualified System.Environment as Sys
15 import qualified System.Exit as Sys
1516
1617 -- | The main driver
1718 main :: IO ()
2324 Nothing -> getContents
2425 Just f -> readFile f
2526 -- attempt to parse it
26 let telml = case TeLML.parse telmlSource of
27 Right str -> str
28 Left err -> error err
27 telml <- case TeLML.parse telmlSource of
28 Right str -> return str
29 Left err -> do
30 putStrLn err
31 Sys.exitFailure
2932 -- read the Lua source file, if provided
3033 luaSource <- case optTagFile options of
3134 Nothing -> return ""
3639 -- either print the result or print the error nicely
3740 case result of
3841 Right msg -> Text.putStr msg
39 Left err -> putStrLn (Exn.displayException err)
42 Left err -> do
43 putStrLn (Exn.displayException err)
44 Sys.exitFailure
4045
4146 -- * Lua stuff
4247
123128
124129 -- * Errors and error-handling
125130
126 -- We wrap the usual LuaHS error type in our own
127
131 -- | We wrap the usual LuaHS error type in our own
128132 data Error
129133 = LuaError Lua.Exception
130134 | TeLMLError Exn.SomeException
307311 Opt.Option
308312 ['t']
309313 ["tags"]
310 (Opt.ReqArg (\f o -> o {optTagFile = Just f}) "[file]")
314 (Opt.ReqArg (\f o -> o {optTagFile = Just f}) "[tagfile.lua]")
311315 "The file of tag definitions to use"
312316 ]
313317
325329 return (foldl (flip id) def flags)
326330 (flags, [input], []) ->
327331 return (foldl (flip id) def flags) {optInputFile = Just input}
328 (_, _, errors) ->
329 error (unlines errors)
332 (_, _, errors) -> do
333 putStr (unlines errors)
334 putStrLn (Opt.usageInfo "USAGE: telml [input.telml] [-n] [-t tagfile.lua]" optionDescriptions)
335 Sys.exitFailure
1010 description: A simple, extensible, TeX-like markup language.
1111 cabal-version: >= 1.10
1212 build-type: Simple
13 extra-source-files: README.md, ChangeLog.md
13 extra-source-files: README.md
1414
1515 executable telml2html
1616 default-language: Haskell2010