[Helper docced and greetings on main Paolo Veronelli **20080207213202] { hunk ./Eval.hs 65 - either (const $ throwError CommandHelpMissing) (maybe (throwError $ Ahi "Boh") output) + either (throwError . CommandHelpParseErr) (maybe (throwError CommandHelpMissing) output) hunk ./Helper.hs 2 +-- | Parse and pretty print the string of help of commands hunk ./Helper.hs 12 - +-- |structure for the help of a command hunk ./Helper.hs 30 +-- |parses a CommandHelp +parseACommandHelp :: CharParser () CommandHelp hunk ./Helper.hs 42 - +-- |parses all commands help +parseCommandsHelp :: CharParser () [CommandHelp] hunk ./Helper.hs 51 -run :: String -> GenParser Char () a -> (a -> Maybe b) -> Either String (Maybe b) -run file p cl = - case (parse p "help parser" file) of - Left err -> Left (show err) - Right cs -> Right $ cl cs +-- |run the parser against a string +run + :: String -- ^ The string to parse + -> GenParser Char () a -- ^ the parser to use + -> (a -> Maybe b) -- ^ a function to use on the result , if it succed + -> Either String (Maybe b) -- ^ the error showed if it fails or the result closed hunk ./Helper.hs 58 -tabulate = foldr1 ($$) . tabulate' . transpose where +run file p cl = either (Left . show) (Right . cl) (parse p "help parser" file) + +-- |create a nice table from lines of words +tabulate :: [[String]] -> String +tabulate = render . foldr1 ($$) . tabulate' . transpose where hunk ./Helper.hs 64 - tabulate' (xs:yss) = let ls = map length xs - tyss = tabulate' yss - in [text x $$ nest (maximum ls + 1) y| x <- xs | y <- tyss] + tabulate' (xs:yss) = [text x $$ nest (maximum (map length xs) + 1) y| x <- xs | y <- tabulate' yss] + +-- |parse a prettyprint of a list of command helps from a string +listOfCommands + :: String -- ^ the string with the help inside + -> Either String (Maybe String) -- ^ a parse error or Just a prettyprint of a list of command helps +listOfCommands file = run file parseCommandsHelp (Just . tabulate . map (\c -> [synopsis c , name c])) hunk ./Helper.hs 72 -listOfCommands file = run file parseCommandsHelp (Just . render. tabulate . map (\c -> [synopsis c , name c])) +-- |parse a prettyprint of a list of command helps from a string +helpCommand + :: String -- ^ the command name + -> String -- ^ the string with the help inside + -> Either String (Maybe String) -- ^ a parse error or (Just the command help or Nothing if the command is missing) hunk ./Main.hs 10 +import Text.PrettyPrint (render,text,nest, (<>),(<+>),($$),sep) hunk ./Main.hs 23 + +-- |launches an external program , catching output and errors, return on exit hunk ./Main.hs 34 + hunk ./Main.hs 37 -programSio = SIO readline putStrLn addHistory putStrLn (handleWith show . strictReadFile) (\x y -> handleWith show (writeFile x y)) externalCommand - +programSio = SIO + readline + putStrLn + addHistory + putStrLn + (handleWith show . strictReadFile) + (\x y -> handleWith show (writeFile x y)) externalCommand hunk ./Main.hs 45 -main = run (commandLoop parse eval) programSio (Stato empty "" Nothing Nothing Nothing) :: IO (Stato InsideAppend) +-- | the greetings +greetings :: IO () +greetings = putStrLn . render $ + text "Hedi command line editor. " <> ( + text "Version 0.1" $$ + text "Released under BSD licence." $$ + text "Copyright 2008 Paolo Veronelli" $$ + text "Homepage http://code.haskell.org/Hedi") + $$ text " " + $$ text "Type \"he\" for help or \"he command\" for help on command" + $$ text "Type \"CTRL-D\" to quit without saving" + +main :: IO () +main = do + run (liftIO greetings >> commandLoop parse eval) + programSio (Stato empty "" Nothing Nothing Nothing) :: IO (Stato InsideAppend) + return () hunk ./docs/Main.html 88 +>greetings :: IO ()main :: IO ()launches an external program , catching output and errors, return on exit +greetings :: IO ()the greetings +main :: IO ()greetingsMainHelperHelperHelperHelperMainMainHelperHelperHelperHelperHelperHelper