16 | module Language.Reflection.Pretty
18 | import Derive.Pretty
20 | import Data.Vect.Quantifiers
21 | import Language.Reflection.Util
22 | import Language.Reflection.TTImp
24 | %language ElabReflection
37 | putDoc : HasIO io => Doc Opts80 -> io ()
38 | putDoc = putStr . render Opts80
42 | putPretty : HasIO io => Pretty t => t -> io ()
43 | putPretty = putDoc . pretty
46 | 0 WithName : Type -> Type
47 | WithName = Pair String
52 | -> {auto _ : All Pretty ts}
55 | -> All Prelude.id ts
57 | conH p str ps = prettyCon p str $
go ps
60 | go : All Pretty ss => All Prelude.id ss -> List (Doc opts)
62 | go @{_ :: _} (v :: ps) = prettyArg v :: go ps
67 | -> {auto _ : All Pretty ts}
72 | recordH p str ps = prettyRecord p str $
go ps
75 | go : All Pretty ss => All WithName ss -> List (Doc opts)
77 | go @{_ :: _} ((fn,v) :: ps) = prettyField fn v :: go ps
85 | -> (args : List (String,Doc opts))
87 | op p fixity fst args@((o,_) :: _) =
89 | opArgs := map (\(x,y) => line {opts} x <++> y) args
90 | sngl := hsep (fst :: opArgs)
91 | mult := vsep (indent (S len) fst :: opArgs)
92 | in parenthesise (p >= User fixity) $
ifMultiline sngl mult
100 | Pretty Namespace where
101 | prettyPrec _ (MkNS xs) = line . concat . intersperse "." $
reverse xs
105 | prettyPrec _ = dquotes . line . show
109 | prettyPrec _ _ = line "emptyFC"
112 | Pretty a => Pretty (WithFC a) where
113 | prettyPrec n x = prettyPrec n x.value
116 | Pretty a => Pretty (WithDefault a def') where
117 | prettyPrec p withDef =
118 | onWithDefault (line "defaulted")
119 | (\v => prettyCon p "specified" [prettyArg v])
122 | %runElab derive "Count" [Pretty]
123 | %runElab derive "PiInfo" [Pretty]
124 | %runElab derive "LazyReason" [Pretty]
125 | %runElab derive "TotalReq" [Pretty]
126 | %runElab derive "Visibility" [Pretty]
127 | %runElab derive "PrimType" [Pretty]
128 | %runElab derive "Constant" [Pretty]
134 | %runElab derive "BindMode" [Pretty]
135 | %runElab derive "UseSide" [Pretty]
136 | %runElab derive "DotReason" [Pretty]
137 | %runElab derive "BuiltinType" [Pretty]
138 | %runElab derive "WithFlag" [Pretty]
139 | %runElab derive "DataOpt" [Pretty]
142 | prettyImplTTImp : Pretty TTImp
145 | prettyImplArg : Pretty Arg
148 | prettyImplClause : Pretty Clause
151 | prettyImplITy : Pretty ITy
153 | %runElab deriveMutual
164 | prettyImplITy = MkPretty $
\p,v => case v of
165 | (MkTy _ n ty) => recordH p "mkTy" [("name", n.value), ("type", ty)]
167 | prettyImplArg = MkPretty $
\p,v =>
168 | conH p "MkArg" [v.count, v.piInfo, v.name, v.type]
170 | prettyImplClause = assert_total $
MkPretty $
\p,v => case v of
171 | PatClause fc lhs rhs =>
172 | op p 3 (prettyPrec (User 3) lhs) [(".=", prettyPrec (User 3) rhs)]
173 | WithClause fc lhs rig wval prf flags cls =>
174 | recordH p "withClause"
182 | ImpossibleClause fc lhs => conH p "impossibleClause" [lhs]
184 | appOp : {opts : _} -> Either String Name -> TTImp -> (String, Doc opts)
185 | appOp (Left x) s = (x, prettyPrec (User 6) s)
186 | appOp (Right x) s = (".!", prettyPrec (User 6) (x,s))
190 | -> List (String,Doc opts)
192 | -> (Doc opts, List (String,Doc opts))
193 | appPairs ps (IApp fc s t) = appPairs (appOp (Left ".$") t :: ps) s
194 | appPairs ps (IAutoApp fc s t) = appPairs (appOp (Left ".@") t :: ps) s
195 | appPairs ps (INamedApp fc s nm t) = appPairs (appOp (Right nm) t :: ps) s
196 | appPairs ps t = (prettyPrec (User 6) t, ps)
198 | prettyImplTTImp = assert_total $
MkPretty $
\p,v => case v of
199 | IVar _ nm => conH p "var" [nm]
201 | IPi _ rig pinfo mnm argTy retTy =>
202 | let (args,res) := unPi retTy
203 | pargs := prettyPrec (User 5) <$> args
204 | pres := prettyPrec (User 5) res
205 | fst := prettyPrec (User 5) $
MkArg rig pinfo mnm argTy
206 | in op p 5 fst $
(".->",) <$> (pargs ++ [pres])
208 | ILam _ rig pinfo mnm argTy lamTy =>
209 | let (args,res) := unLambda lamTy
210 | pargs := prettyPrec (User 3) <$> args
211 | pres := prettyPrec (User 3) res
212 | fst := prettyPrec (User 3) $
MkArg rig pinfo mnm argTy
213 | in op p 3 fst $
(".=>",) <$> (pargs ++ [pres])
215 | ILet _ _ rig nm nTy nVal scope =>
224 | ICase _ _ s ty cls =>
225 | recordH p "iCase" [("sc", s), ("ty", ty), ("clauses", cls)]
227 | ILocal _ decls s => recordH p "local" [("decls", decls), ("scope", s)]
229 | IUpdate _ upds s => recordH p "update" [("updates", upds), ("arg", s)]
232 | let (fst,ps) := appPairs [appOp (Left ".$") t] s
235 | INamedApp _ s nm t =>
236 | let (fst,ps) := appPairs [appOp (Right nm) t] s
240 | let (fst,ps) := appPairs [appOp (Left ".@") t] s
243 | IWithApp _ s t => recordH p "withApp" [("fun", s), ("arg", t)]
244 | ISearch _ depth => conH p "iSearch" [depth]
245 | IAlternative _ x ss => recordH p "alternative" [("tpe", x), ("alts", ss)]
246 | IRewrite _ s t => recordH p "iRewrite" [("eq", s), ("scope", t)]
247 | IBindHere _ bm s => recordH p "bindHere" [("mode", bm), ("arg", s)]
248 | IBindVar _ str => conH p "bindVar" [str]
249 | IAs _ _ side nm s =>
250 | recordH p "iAs" [("side", side), ("name", nm), ("val", s)]
251 | IMustUnify _ dr s => recordH p "mustUnify" [("reason", dr), ("val", s)]
252 | IDelayed _ lr s => recordH p "iDelayed" [("reason", lr), ("arg", s)]
253 | IDelay _ s => conH p "iDelay" [s]
254 | IForce _ s => conH p "iForce" [s]
255 | IQuote _ s => conH p "quote" [s]
256 | IQuoteName _ nm => conH p "quoteName" [nm]
257 | IQuoteDecl _ decls => conH p "quoteName" [decls]
258 | IUnquote _ s => conH p "unquote" [s]
259 | IPrimVal _ c => conH p "primVal" [c]
260 | IType _ => line "type"
261 | IHole _ str => conH p "hole" [str]
262 | Implicit _ False => line "implicitFalse"
263 | Implicit _ True => line "implicitTrue"
264 | IWithUnambigNames fc xs s => conH p "IWithUnambigNames" [fc, xs, s]
271 | Pretty (Fin n) where
272 | prettyPrec _ = line . show
274 | %runElab deriveIndexed "MissingInfo" [Pretty]
275 | %runElab deriveIndexed "AppArg" [Pretty]
278 | Pretty (All AppArg vs) where
279 | prettyPrec _ vs = list $
go vs
282 | go : All AppArg bs -> List (Doc opts)
284 | go (x :: y) = pretty x :: go y
286 | %runElab deriveIndexed "Con" [Pretty]
287 | %runElab deriveIndexed "TypeInfo" [Pretty]
288 | %runElab deriveIndexed "ParamTag" [Pretty]
291 | Pretty (ParamPattern m n) where
292 | prettyPrec _ vs = list $
go vs
295 | go : ParamPattern x y -> List (Doc opts)
297 | go (x :: y) = pretty x :: go y
299 | %runElab deriveIndexed "PArg" [Pretty]
300 | %runElab deriveIndexed "ConArg" [Pretty]
301 | %runElab deriveIndexed "ParamCon" [Pretty]
302 | %runElab deriveIndexed "ParamTypeInfo" [Pretty]