@@ -26,23 +26,49 @@ import Debug.Trace
2626bugaddr = "https://github.com/idris-lang/Idris-dev/issues"
2727
2828-- | Re-add syntactic sugar in a term
29−resugar :: PTerm -> PTerm
30−resugar = transform resugarApp
29+resugar :: IState -> PTerm -> PTerm
30+resugar ist = transform flattenDoLet . transform resugarApp
3131 where
3232 resugarApp (PApp fc (PRef _ n) args)
3333 | [c, t, f] <- mapMaybe explicitTerm args
3434 , basename n == sUN "ifThenElse"
3535 = PIfThenElse fc c (dedelay t) (dedelay f)
36+ resugarApp (PApp fc (PRef _ n) args)
37+ | [v, PLam _ bn _ _ next] <- mapMaybe explicitTerm args
38+ , basename n == sUN ">>="
39+ = let step = if bn `elem` namesIn [] ist next
40+ then DoBind fc bn NoFC v
41+ else DoExp NoFC v
42+ in case resugarApp next of
43+ PDoBlock dos -> PDoBlock (step : dos)
44+ expr -> PDoBlock [step, DoExp NoFC expr]
45+ resugarApp (PApp fc (PRef _ n) args)
46+ | [PConstant fc (BI i)] <- mapMaybe explicitTerm args
47+ , basename n == sUN "fromInteger"
48+ = PConstant fc (BI i)
3649 resugarApp tm = tm
50+
51+ flattenDoLet (PLet _ ln _ ty v bdy)
52+ | PDoBlock dos <- flattenDoLet bdy
53+ = PDoBlock (DoLet NoFC ln NoFC ty v : dos)
54+ flattenDoLet (PDoBlock dos) =
55+ PDoBlock $ concatMap fixExp dos
56+ where fixExp (DoExp _ (PLet _ ln _ ty v bdy)) =
57+ DoLet NoFC ln NoFC ty v : fixExp (DoExp NoFC bdy)
58+ fixExp d = [d]
59+ flattenDoLet tm = tm
60+
3761 dedelay (PApp _ (PRef _ delay) [_, _, obj])
3862 | delay == sUN "Delay" = getTm obj
3963 dedelay x = x
64+
4065 explicitTerm (PExp {getTm = tm}) = Just tm
4166 explicitTerm _ = Nothing
4267
68+
4369-- | Delaborate and resugar a term
4470delabSugared :: IState -> Term -> PTerm
45−delabSugared ist tm = resugar $ delab ist tm
71+delabSugared ist tm = resugar ist $ delab ist tm
4672
4773-- | Delaborate a term without resugaring
4874delab :: IState -> Term -> PTerm
@@ -205,8 +231,8 @@ pprintDelabTy i n
205231 = case lookupTy n (tt_ctxt i) of
206232 (ty:_) -> annotate (AnnTerm [] ty) . prettyIst i $
207233 case lookupCtxt n (idris_implicits i) of
208− (imps:_) -> resugar $ delabTy' i imps ty False False
209− _ -> resugar $ delabTy' i [] ty False False
234+ (imps:_) -> resugar i $ delabTy' i imps ty False False
235+ _ -> resugar i $ delabTy' i [] ty False False
210236 [] -> error "pprintDelabTy got a name that doesn't exist"
211237
212238pprintTerm :: IState -> PTerm -> Doc OutputAnnotation
@@ -564,7 +590,7 @@ fancifyAnnots ist meta annot@(AnnName n _ _ _) =
564590 return (out "")
565591 getTy :: IState -> Name -> String -- fails if name not already extant!
566592 getTy ist n = let theTy = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist) $
567− resugar $ delabTy ist n
593+ resugar ist $ delabTy ist n
568594 in (displayS . renderPretty 1.0 50 $ theTy) ""
569595fancifyAnnots _ _ annot = annot
570596