@@ -30,6 +30,7 @@ import Idris.Inliner
30import Idris.CaseSplit
30import Idris.CaseSplit
31import Idris.DeepSeq
31import Idris.DeepSeq
32import Idris.Output
32import Idris.Output
33+import Idris.Interactive
33import Idris.WhoCalls
34import Idris.WhoCalls
35import Paths_idris
36import Paths_idris
@@ -698,186 +699,18 @@ process h fn (DebugInfo n)
698 when (not (null cg')) $ do iputStrLn "Call graph:\n"
699 when (not (null cg')) $ do iputStrLn "Call graph:\n"
699 iputStrLn (show cg')
700 iputStrLn (show cg')
700process h fn (Search t) = iPrintError "Not implemented"
701process h fn (Search t) = iPrintError "Not implemented"
701−-- FIXME: There is far too much repetition in the cases below!
702−process h fn (CaseSplitAt updatefile l n)
702+process h fn (CaseSplitAt updatefile l n)
703− = do src <- runIO $ readFile fn
703+ = caseSplitAt h fn updatefile l n
704− res <- splitOnLine l n fn
705− iLOG (showSep "\n" (map show res))
706− let (before, (ap : later)) = splitAt (l-1) (lines src)
707− res' <- replaceSplits ap res
708− let new = concat res'
710− then do let fb = fn ++ "~" -- make a backup!
711− runIO $ writeFile fb (unlines before ++ new ++ unlines later)
712− runIO $ copyFile fb fn
713− else -- do ihputStrLn h (show res)
715process h fn (AddClauseFrom updatefile l n)
704process h fn (AddClauseFrom updatefile l n)
716− = do src <- runIO $ readFile fn
717− let (before, tyline : later) = splitAt (l-1) (lines src)
718− let indent = getIndent 0 (show n) tyline
719− cl <- getClause l n fn
720− -- add clause before first blank line in 'later'
721− let (nonblank, rest) = span (not . all isSpace) (tyline:later)
722− if updatefile
705+ = addClauseFrom h fn updatefile l n
723− then do let fb = fn ++ "~"
724− runIO $ writeFile fb (unlines (before ++ nonblank) ++
725− replicate indent ' ' ++
728− runIO $ copyFile fb fn
729− else ihPrintResult h cl
731− getIndent i n [] = 0
732− getIndent i n xs | take (length n) xs == n = i
733− getIndent i n (x : xs) = getIndent (i + 1) n xs
734process h fn (AddProofClauseFrom updatefile l n)
706process h fn (AddProofClauseFrom updatefile l n)
735− = do src <- runIO $ readFile fn
736− let (before, tyline : later) = splitAt (l-1) (lines src)
737− let indent = getIndent 0 (show n) tyline
738− cl <- getProofClause l n fn
739− -- add clause before first blank line in 'later'
740− let (nonblank, rest) = span (not . all isSpace) (tyline:later)
741− if updatefile
707+ = addProofClauseFrom h fn updatefile l n
742− then do let fb = fn ++ "~"
743− runIO $ writeFile fb (unlines (before ++ nonblank) ++
744− replicate indent ' ' ++
747− runIO $ copyFile fb fn
748− else ihPrintResult h cl
750− getIndent i n [] = 0
751− getIndent i n xs | take (length n) xs == n = i
752− getIndent i n (x : xs) = getIndent (i + 1) n xs
753process h fn (AddMissing updatefile l n)
708process h fn (AddMissing updatefile l n)
754− = do src <- runIO $ readFile fn
709+ = addMissing h fn updatefile l n
755− let (before, tyline : later) = splitAt (l-1) (lines src)
756− let indent = getIndent 0 (show n) tyline
758− cl <- getInternalApp fn l
759− let n' = getAppName cl
761− extras <- case lookupCtxt n' (idris_patdefs i) of
763− [(_, tms)] -> do tms' <- nameMissing tms
764− showNew (show n ++ "_rhs") 1 indent tms'
765− let (nonblank, rest) = span (not . all isSpace) (tyline:later)
767− then do let fb = fn ++ "~"
768− runIO $ writeFile fb (unlines (before ++ nonblank)
769− ++ extras ++ unlines rest)
770− runIO $ copyFile fb fn
771− else ihPrintResult h extras
772− where showPat = show . stripNS
773− stripNS tm = mapPT dens tm where
774− dens (PRef fc n) = PRef fc (nsroot n)
777− nsroot (NS n _) = nsroot n
778− nsroot (SN (WhereN _ _ n)) = nsroot n
781− getAppName (PApp _ r _) = getAppName r
782− getAppName (PRef _ r) = r
785− showNew nm i ind (tm : tms)
786− = do (nm', i') <- getUniq nm i
787− rest <- showNew nm i' ind tms
788− return (replicate ind ' ' ++
789− showPat tm ++ " = ?" ++ nm' ++
791− showNew nm i _ [] = return ""
793− getIndent i n [] = 0
794− getIndent i n xs | take (length n) xs == n = i
795− getIndent i n (x : xs) = getIndent (i + 1) n xs
797process h fn (MakeWith updatefile l n)
710process h fn (MakeWith updatefile l n)
798− = do src <- runIO $ readFile fn
711+ = makeWith h fn updatefile l n
799− let (before, tyline : later) = splitAt (l-1) (lines src)
800− let ind = getIndent tyline
801− let with = mkWith tyline n
802− -- add clause before first blank line in 'later',
803− -- or (TODO) before first line with same indentation as tyline
804− let (nonblank, rest) = span (\x -> not (all isSpace x) &&
805− not (ind == getIndent x)) later
807− do let fb = fn ++ "~"
808− runIO $ writeFile fb (unlines (before ++ nonblank)
811− runIO $ copyFile fb fn
812− else ihPrintResult h with
813− where getIndent s = length (takeWhile isSpace s)
815process h fn (DoProofSearch updatefile rec l n hints)
712process h fn (DoProofSearch updatefile rec l n hints)
816− = do src <- runIO $ readFile fn
713+ = doProofSearch h fn updatefile rec l n hints
817− let (before, tyline : later) = splitAt (l-1) (lines src)
819− mn <- case lookupNames n ctxt of
822− ns -> ierror (CantResolveAlts (map show ns))
824− let (top, envlen, _) = case lookup mn (idris_metavars i) of
825− Just (t, e, False) -> (t, e, False)
826− _ -> (Nothing, 0, True)
828− let body t = PProof [Try (TSeq Intros (ProofSearch rec t hints))
829− (ProofSearch rec t hints)]
830− let def = PClause fc mn (PRef fc mn) [] (body top) []
832− (do elabDecl' EAll toplevel (PClauses fc [] mn [def])
833− (tm, ty) <- elabVal toplevel False (PRef fc mn)
836− return . flip displayS "" . renderPretty 1.0 80 $
837− pprintPTerm defaultPPOption [] [] (idris_infixes i)
840− (delab i (specialise ctxt [] [(mn, 1)] tm)))))
841− (\e -> return ("?" ++ show n))
843− do let fb = fn ++ "~"
844− runIO $ writeFile fb (unlines before ++
845− updateMeta False tyline (show n) newmv ++ "\n"
847− runIO $ copyFile fb fn
848− else ihPrintResult h newmv
849− where dropCtxt 0 sc = sc
850− dropCtxt i (PPi _ _ _ sc) = dropCtxt (i - 1) sc
851− dropCtxt i (PLet _ _ _ sc) = dropCtxt (i - 1) sc
852− dropCtxt i (PLam _ _ sc) = dropCtxt (i - 1) sc
855− stripNS tm = mapPT dens tm where
856− dens (PRef fc n) = PRef fc (nsroot n)
859− nsroot (NS n _) = nsroot n
860− nsroot (SN (WhereN _ _ n)) = nsroot n
863− updateMeta brack ('?':cs) n new
864− | length cs >= length n
865− = case splitAt (length n) cs of
867− if ((isSpace c || c == ')' || c == '}') && mv == n)
868− then addBracket brack new ++ (c : cs)
869− else '?' : mv ++ c : updateMeta True cs n new
870− (mv, []) -> if (mv == n) then addBracket brack new else '?' : mv
871− updateMeta brack ('=':cs) n new = '=':updateMeta False cs n new
872− updateMeta brack (c:cs) n new
873− = c : updateMeta (brack || not (isSpace c)) cs n new
874− updateMeta brack [] n new = ""
876− addBracket False new = new
877− addBracket True new@('(':xs) | last xs == ')' = new
878− addBracket True new | any isSpace new = '(' : new ++ ")"
881process h fn (Spec t)
714process h fn (Spec t)
882 = do (tm, ty) <- elabVal toplevel False t
715 = do (tm, ty) <- elabVal toplevel False t
883 ctxt <- getContext
716 ctxt <- getContext