@@ -79,11 +79,6 @@ processInput cmd orig inputs
79 return (Just inputs)
79 return (Just inputs)
80 Right Edit -> do edit fn orig
80 Right Edit -> do edit fn orig
81 return (Just inputs)
81 return (Just inputs)
82− Right AddProof -> do idrisCatch (addProof fn orig)
83− (\e -> iputStrLn (show e))
85− Right RmProof -> do rmProof orig
87 Right Proofs -> do proofs orig
82 Right Proofs -> do proofs orig
88 return (Just inputs)
83 return (Just inputs)
89 Right Quit -> do iputStrLn "Bye bye"
84 Right Quit -> do iputStrLn "Bye bye"
@@ -92,6 +87,23 @@ processInput cmd orig inputs
92 (\e -> iputStrLn (show e))
87 (\e -> iputStrLn (show e))
93 return (Just inputs)
88 return (Just inputs)
90+resolveProof :: Name -> Idris Name
94+ n <- case lookupNames Nothing n' ctxt of
97+ ns -> fail $ pshow i (CantResolveAlts (map show ns))
100+removeProof :: Name -> Idris ()
103+ let proofs = proof_list i
104+ let ps = filter ((/= n) . fst) proofs
105+ put $ i { proof_list = ps }
95edit :: FilePath -> IState -> Idris ()
107edit :: FilePath -> IState -> Idris ()
96edit "" orig = iputStrLn "Nothing to edit"
108edit "" orig = iputStrLn "Nothing to edit"
97edit f orig
109edit f orig
@@ -112,38 +124,14 @@ edit f orig
112 | Just ed <- lookup "VISUAL" env = ed
124 | Just ed <- lookup "VISUAL" env = ed
113 | otherwise = "vi"
125 | otherwise = "vi"
115−addProof :: FilePath -> IState -> Idris ()
116−addProof "" orig = iputStrLn "Nothing to add to"
118− = do let fb = f ++ "~"
119− liftIO $ copyFile f fb -- make a backup in case something goes wrong!
120− prog <- liftIO $ readFile fb
122− case proof_list i of
123− [] -> iputStrLn "No proof to add"
124− (n, p) : proofs -> do let prog' = insertScript (showProof (lit f) n p) (lines prog)
125− liftIO $ writeFile f (unlines prog')
126− iputStrLn $ "Added proof " ++ show n
127− put (i { proof_list = proofs })
128− -- lift $ removeFile fb -- uncomment when less scared :)
130−rmProof :: IState -> Idris ()
133− case proof_list i of
134− [] -> iputStrLn "Nothing to remove"
135− (n, p) : ps -> do iputStrLn $ "Removed proof " ++ show n
136− let metavars = idris_metavars i
137− put (i { proof_list = ps
138− , idris_metavars = n : metavars
141proofs :: IState -> Idris ()
128proofs :: IState -> Idris ()
142proofs orig
129proofs orig
143 = do i <- get
130 = do i <- get
144− case proof_list i of
131+ let ps = proof_list i
145− [] -> iputStrLn "No proofs"
133+ [] -> iputStrLn "No proofs available"
146− ps -> mapM_ (\(n, p) -> iputStrLn $ showProof False n p) ps
134+ _ -> iputStrLn $ "Proofs:\n\t" ++ (show $ map fst ps)
148insertScript :: String -> [String] -> [String]
136insertScript :: String -> [String] -> [String]
149insertScript prf [] = "\n---------- Proofs ----------" : "" : [prf]
137insertScript prf [] = "\n---------- Proofs ----------" : "" : [prf]
@@ -246,19 +234,60 @@ process fn (Spec t) = do (tm, ty) <- elabVal toplevel False t
246 ist <- get
234 ist <- get
247 let tm' = specialise ctxt [] [] {- (idris_statics ist) -} tm
235 let tm' = specialise ctxt [] [] {- (idris_statics ist) -} tm
248 iputStrLn (show (delab ist tm'))
236 iputStrLn (show (delab ist tm'))
238+process fn (RmProof n')
240+ n <- resolveProof n'
241+ let proofs = proof_list i
242+ case lookup n proofs of
243+ Nothing -> iputStrLn "No proof to remove"
244+ Just _ -> do removeProof n
246+ iputStrLn $ "Removed proof " ++ show n
248+ insertMetavar :: Name -> Idris ()
251+ let ms = idris_metavars i
252+ put $ i { idris_metavars = n : ms }
254+process fn (AddProof n')
255+ = do let fb = fn ++ "~"
256+ liftIO $ copyFile fn fb -- make a backup in case something goes wrong!
257+ prog <- liftIO $ readFile fb
259+ n <- resolveProof n'
260+ let proofs = proof_list i
261+ case lookup n proofs of
262+ Nothing -> iputStrLn "No proof to add"
263+ Just p -> do let prog' = insertScript (showProof (lit fn) n p) ls
264+ liftIO $ writeFile fn (unlines prog')
266+ iputStrLn $ "Added proof " ++ show n
267+ where ls = (lines prog)
269+process fn (ShowProof n')
271+ n <- resolveProof n'
272+ let proofs = proof_list i
273+ case lookup n proofs of
274+ Nothing -> iputStrLn "No proof to show"
275+ Just p -> iputStrLn $ showProof False n p
249−process fn (Prove n')
277+process fn (Prove n')
250 = do ctxt <- getContext
278 = do ctxt <- getContext
251 ist <- get
279 ist <- get
252 n <- case lookupNames Nothing n' ctxt of
280 n <- case lookupNames Nothing n' ctxt of
253 [x] -> return x
281 [x] -> return x
254 [] -> return n'
282 [] -> return n'
255− ns -> fail $ pshow ist (CantResolveAlts (map show ns))
283+ ns -> fail $ pshow ist (CantResolveAlts (map show ns))
256 prover (lit fn) n
284 prover (lit fn) n
257 -- recheck totality
285 -- recheck totality
259 totcheck (FC "(input)" 0, n)
287 totcheck (FC "(input)" 0, n)
260 mapM_ (\ (f,n) -> setTotality n Unchecked) (idris_totcheck i)
288 mapM_ (\ (f,n) -> setTotality n Unchecked) (idris_totcheck i)
261 mapM_ checkDeclTotality (idris_totcheck i)
289 mapM_ checkDeclTotality (idris_totcheck i)
262process fn (HNF t) = do (tm, ty) <- elabVal toplevel False t
291process fn (HNF t) = do (tm, ty) <- elabVal toplevel False t
263 ctxt <- getContext
292 ctxt <- getContext
264 ist <- get
293 ist <- get
@@ -353,9 +382,10 @@ help =
353 ([":e",":edit"], "", "Edit current file using $EDITOR or $VISUAL"),
382 ([":e",":edit"], "", "Edit current file using $EDITOR or $VISUAL"),
354 ([":m",":metavars"], "", "Show remaining proof obligations (metavariables)"),
383 ([":m",":metavars"], "", "Show remaining proof obligations (metavariables)"),
355 ([":p",":prove"], "<name>", "Prove a metavariable"),
384 ([":p",":prove"], "<name>", "Prove a metavariable"),
356− ([":a",":addproof"], "", "Add last proof to source file"),
385+ ([":a",":addproof"], "<name>", "Add proof to source file"),
357− ([":rmproof"], "", "Remove last proof from proof stack"),
386+ ([":rmproof"], "<name>", "Remove proof from proof stack"),
358− ([":proofs"], "", "Show proof stack"),
387+ ([":showproof"], "<name>", "Show proof"),
388+ ([":proofs"], "", "Show available proofs"),
359 ([":c",":compile"], "<filename>", "Compile to an executable <filename>"),
389 ([":c",":compile"], "<filename>", "Compile to an executable <filename>"),
360 ([":exec",":execute"], "", "Compile to an executable and run"),
390 ([":exec",":execute"], "", "Compile to an executable and run"),
361 ([":?",":h",":help"], "", "Display this help text"),
391 ([":?",":h",":help"], "", "Display this help text"),