@@ -26,23 +26,49 @@ import Debug.Trace
26bugaddr = "https://github.com/idris-lang/Idris-dev/issues"
26bugaddr = "https://github.com/idris-lang/Idris-dev/issues"
28-- | Re-add syntactic sugar in a term
28-- | Re-add syntactic sugar in a term
29−resugar :: PTerm -> PTerm
29+resugar :: IState -> PTerm -> PTerm
30−resugar = transform resugarApp
30+resugar ist = transform flattenDoLet . transform resugarApp
32 resugarApp (PApp fc (PRef _ n) args)
32 resugarApp (PApp fc (PRef _ n) args)
33 | [c, t, f] <- mapMaybe explicitTerm args
33 | [c, t, f] <- mapMaybe explicitTerm args
34 , basename n == sUN "ifThenElse"
34 , basename n == sUN "ifThenElse"
35 = PIfThenElse fc c (dedelay t) (dedelay f)
35 = 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
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)
36 resugarApp tm = tm
49 resugarApp tm = tm
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)
37 dedelay (PApp _ (PRef _ delay) [_, _, obj])
61 dedelay (PApp _ (PRef _ delay) [_, _, obj])
38 | delay == sUN "Delay" = getTm obj
62 | delay == sUN "Delay" = getTm obj
39 dedelay x = x
63 dedelay x = x
40 explicitTerm (PExp {getTm = tm}) = Just tm
65 explicitTerm (PExp {getTm = tm}) = Just tm
41 explicitTerm _ = Nothing
66 explicitTerm _ = Nothing
43-- | Delaborate and resugar a term
69-- | Delaborate and resugar a term
44delabSugared :: IState -> Term -> PTerm
70delabSugared :: IState -> Term -> PTerm
45−delabSugared ist tm = resugar $ delab ist tm
71+delabSugared ist tm = resugar ist $ delab ist tm
47-- | Delaborate a term without resugaring
73-- | Delaborate a term without resugaring
48delab :: IState -> Term -> PTerm
74delab :: IState -> Term -> PTerm
@@ -205,8 +231,8 @@ pprintDelabTy i n
205 = case lookupTy n (tt_ctxt i) of
231 = case lookupTy n (tt_ctxt i) of
206 (ty:_) -> annotate (AnnTerm [] ty) . prettyIst i $
232 (ty:_) -> annotate (AnnTerm [] ty) . prettyIst i $
207 case lookupCtxt n (idris_implicits i) of
233 case lookupCtxt n (idris_implicits i) of
208− (imps:_) -> resugar $ delabTy' i imps ty False False
234+ (imps:_) -> resugar i $ delabTy' i imps ty False False
209− _ -> resugar $ delabTy' i [] ty False False
235+ _ -> resugar i $ delabTy' i [] ty False False
210 [] -> error "pprintDelabTy got a name that doesn't exist"
236 [] -> error "pprintDelabTy got a name that doesn't exist"
212pprintTerm :: IState -> PTerm -> Doc OutputAnnotation
238pprintTerm :: IState -> PTerm -> Doc OutputAnnotation
@@ -564,7 +590,7 @@ fancifyAnnots ist meta annot@(AnnName n _ _ _) =
564 return (out "")
590 return (out "")
565 getTy :: IState -> Name -> String -- fails if name not already extant!
591 getTy :: IState -> Name -> String -- fails if name not already extant!
566 getTy ist n = let theTy = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist) $
592 getTy ist n = let theTy = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist) $
567− resugar $ delabTy ist n
593+ resugar ist $ delabTy ist n
568 in (displayS . renderPretty 1.0 50 $ theTy) ""
594 in (displayS . renderPretty 1.0 50 $ theTy) ""
569fancifyAnnots _ _ annot = annot
595fancifyAnnots _ _ annot = annot