@@ -22,6 +22,7 @@ import System.Console.Readline
2222import System.FilePath
2323import System.Environment
2424import System.Process
25+import System.Directory
2526import Control.Monad
2627import Control.Monad.State
2728import Data.List
@@ -60,6 +61,9 @@ processInput cmd orig inputs
6061 return (Just inputs)
6162 Right Edit -> do edit fn orig
6263 return (Just inputs)
64+ Right AddProof -> do idrisCatch (addProof fn orig)
65+ (\e -> iputStrLn (report e))
66+ return (Just inputs)
6367 Right Quit -> do iputStrLn "Bye bye"
6468 return Nothing
6569 Right cmd -> do idrisCatch (process cmd)
@@ -85,6 +89,26 @@ edit f orig
8589 | Just ed <- lookup "VISUAL" env = ed
8690 | otherwise = "vi"
8791
92+addProof :: FilePath -> IState -> Idris ()
93+addProof "" orig = iputStrLn "Nothing to add to"
94+addProof f orig
95+ = do let fb = f ++ "~"
96+ lift $ copyFile f fb -- make a backup in case something goes wrong!
97+ prog <- lift $ readFile fb
98+ i <- get
99+ case last_proof i of
100+ Nothing -> iputStrLn "No proof to add"
101+ Just (n, p) -> do let prog' = insertScript (showProof n p) (lines prog)
102+ lift $ writeFile f (unlines prog')
103+ iputStrLn $ "Added proof " ++ show n
104+ -- lift $ removeFile fb -- uncomment when less scared :)
105+
106+insertScript :: String -> [String] -> [String]
107+insertScript prf [] = "\n---------- Proofs ----------" : "" : [prf]
108+insertScript prf (p@"---------- Proofs ----------" : "" : xs)
109+ = p : "" : prf : xs
110+insertScript prf (x : xs) = x : insertScript prf xs
111+
88112process :: Command -> Idris ()
89113process Help = iputStrLn displayHelp
90114process (Eval t) = do (tm, ty) <- elabVal toplevel False t
@@ -149,7 +173,7 @@ displayHelp = let vstr = showVersion version in
149173 "\nIdris version " ++ vstr ++ "\n" ++
150174 "--------------" ++ map (\x -> '-') vstr ++ "\n\n" ++
151175 concatMap cmdInfo help
152− where cmdInfo (cmds, args, text) = " " ++ col 16 12 (showSep " " cmds) args text
176+ where cmdInfo (cmds, args, text) = " " ++ col 16 10 (showSep " " cmds) args text
153177 col c1 c2 l m r =
154178 l ++ take (c1 - length l) (repeat ' ') ++
155179 m ++ take (c2 - length m) (repeat ' ') ++ r ++ "\n"
@@ -157,12 +181,13 @@ displayHelp = let vstr = showVersion version in
157181help =
158182 [ (["Command"], "Arguments", "Purpose"),
159183 ([""], "", ""),
160− (["<expression>"], "", "Evaluate an expression"),
161− ([":t"], "<expression>", "Check the type of an expression"),
184+ (["<expr>"], "", "Evaluate an expression"),
185+ ([":t"], "<expr>", "Check the type of an expression"),
162186 ([":r",":reload"], "", "Reload current file"),
163187 ([":e",":edit"], "", "Edit current file using $EDITOR or $VISUAL"),
164188 ([":m",":metavars"], "", "Show remaining proof obligations (metavariables)"),
165189 ([":p",":prove"], "<name>", "Prove a metavariable"),
190+ ([":a",":addproof"], "", "Add last proof to source file"),
166191 ([":c",":compile"], "<filename>", "Compile to an executable <filename>"),
167192 ([":exec",":execute"], "<filename>", "Compile to an executable <filename> and run"),
168193 ([":?",":h",":help"], "", "Display this help text"),