@@ -22,6 +22,7 @@ import System.Console.Readline
22import System.FilePath
22import System.FilePath
23import System.Environment
23import System.Environment
24import System.Process
24import System.Process
25+import System.Directory
25import Control.Monad
26import Control.Monad
26import Control.Monad.State
27import Control.Monad.State
27import Data.List
28import Data.List
@@ -60,6 +61,9 @@ processInput cmd orig inputs
60 return (Just inputs)
61 return (Just inputs)
61 Right Edit -> do edit fn orig
62 Right Edit -> do edit fn orig
62 return (Just inputs)
63 return (Just inputs)
64+ Right AddProof -> do idrisCatch (addProof fn orig)
65+ (\e -> iputStrLn (report e))
63 Right Quit -> do iputStrLn "Bye bye"
67 Right Quit -> do iputStrLn "Bye bye"
64 return Nothing
68 return Nothing
65 Right cmd -> do idrisCatch (process cmd)
69 Right cmd -> do idrisCatch (process cmd)
@@ -85,6 +89,26 @@ edit f orig
85 | Just ed <- lookup "VISUAL" env = ed
89 | Just ed <- lookup "VISUAL" env = ed
86 | otherwise = "vi"
90 | otherwise = "vi"
92+addProof :: FilePath -> IState -> Idris ()
93+addProof "" orig = iputStrLn "Nothing to add to"
95+ = do let fb = f ++ "~"
96+ lift $ copyFile f fb -- make a backup in case something goes wrong!
97+ prog <- lift $ readFile fb
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 :)
106+insertScript :: String -> [String] -> [String]
107+insertScript prf [] = "\n---------- Proofs ----------" : "" : [prf]
108+insertScript prf (p@"---------- Proofs ----------" : "" : xs)
110+insertScript prf (x : xs) = x : insertScript prf xs
88process :: Command -> Idris ()
112process :: Command -> Idris ()
89process Help = iputStrLn displayHelp
113process Help = iputStrLn displayHelp
90process (Eval t) = do (tm, ty) <- elabVal toplevel False t
114process (Eval t) = do (tm, ty) <- elabVal toplevel False t
@@ -149,7 +173,7 @@ displayHelp = let vstr = showVersion version in
149 "\nIdris version " ++ vstr ++ "\n" ++
173 "\nIdris version " ++ vstr ++ "\n" ++
150 "--------------" ++ map (\x -> '-') vstr ++ "\n\n" ++
174 "--------------" ++ map (\x -> '-') vstr ++ "\n\n" ++
151 concatMap cmdInfo help
175 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
153 col c1 c2 l m r =
177 col c1 c2 l m r =
154 l ++ take (c1 - length l) (repeat ' ') ++
178 l ++ take (c1 - length l) (repeat ' ') ++
155 m ++ take (c2 - length m) (repeat ' ') ++ r ++ "\n"
179 m ++ take (c2 - length m) (repeat ' ') ++ r ++ "\n"
@@ -157,12 +181,13 @@ displayHelp = let vstr = showVersion version in
158 [ (["Command"], "Arguments", "Purpose"),
182 [ (["Command"], "Arguments", "Purpose"),
159 ([""], "", ""),
183 ([""], "", ""),
160− (["<expression>"], "", "Evaluate an expression"),
184+ (["<expr>"], "", "Evaluate an expression"),
161− ([":t"], "<expression>", "Check the type of an expression"),
185+ ([":t"], "<expr>", "Check the type of an expression"),
162 ([":r",":reload"], "", "Reload current file"),
186 ([":r",":reload"], "", "Reload current file"),
163 ([":e",":edit"], "", "Edit current file using $EDITOR or $VISUAL"),
187 ([":e",":edit"], "", "Edit current file using $EDITOR or $VISUAL"),
164 ([":m",":metavars"], "", "Show remaining proof obligations (metavariables)"),
188 ([":m",":metavars"], "", "Show remaining proof obligations (metavariables)"),
165 ([":p",":prove"], "<name>", "Prove a metavariable"),
189 ([":p",":prove"], "<name>", "Prove a metavariable"),
190+ ([":a",":addproof"], "", "Add last proof to source file"),
166 ([":c",":compile"], "<filename>", "Compile to an executable <filename>"),
191 ([":c",":compile"], "<filename>", "Compile to an executable <filename>"),
167 ([":exec",":execute"], "<filename>", "Compile to an executable <filename> and run"),
192 ([":exec",":execute"], "<filename>", "Compile to an executable <filename> and run"),
168 ([":?",":h",":help"], "", "Display this help text"),
193 ([":?",":h",":help"], "", "Display this help text"),