%default total

This commit is contained in:
rhiannon morris 2023-10-20 05:28:42 +02:00
parent 5f6eab248d
commit 61060e69c8
2 changed files with 161 additions and 154 deletions

View File

@ -7,6 +7,8 @@ import System.File
import Quox.Pretty import Quox.Pretty
%default total
%hide Text.PrettyPrint.Prettyprinter.Doc.infixr.(<++>) %hide Text.PrettyPrint.Prettyprinter.Doc.infixr.(<++>)

View File

@ -13,6 +13,8 @@ import Derive.Prelude
%language ElabReflection %language ElabReflection
%hide TT.Name %hide TT.Name
%default total
public export public export
record NameContexts d n where record NameContexts d n where
@ -246,10 +248,26 @@ where
hangDSingle "with quantities" $ hangDSingle "with quantities" $
separateTight !commaD $ toSnocList' !(traverse prettyQty qs)] separateTight !commaD $ toSnocList' !(traverse prettyQty qs)]
export parameters {opts : LayoutOpts} (showContext : Bool)
prettyErrorNoLoc : {opts : _} -> (showContext : Bool) -> Error -> export
Eff Pretty (Doc opts) inContext' : Bool -> a -> (a -> Eff Pretty (Doc opts)) ->
prettyErrorNoLoc showContext = \case Doc opts -> Eff Pretty (Doc opts)
inContext' null ctx f doc =
if showContext && not null then
pure $ vappend doc (sep ["in context", !(f ctx)])
else pure doc
export %inline
inTContext : TyContext d n -> Doc opts -> Eff Pretty (Doc opts)
inTContext ctx = inContext' (null ctx) ctx prettyTyContext
export %inline
inEContext : EqContext n -> Doc opts -> Eff Pretty (Doc opts)
inEContext ctx = inContext' (null ctx) ctx prettyEqContext
export
prettyErrorNoLoc : Error -> Eff Pretty (Doc opts)
prettyErrorNoLoc err0 = case err0 of
ExpectedTYPE _ ctx s => ExpectedTYPE _ ctx s =>
hangDSingle "expected a type universe, but got" hangDSingle "expected a type universe, but got"
!(prettyTerm ctx.dnames ctx.tnames s) !(prettyTerm ctx.dnames ctx.tnames s)
@ -348,14 +366,14 @@ prettyErrorNoLoc showContext = \case
[hangDSingle "while checking" !(prettyTerm ctx.dnames ctx.tnames s), [hangDSingle "while checking" !(prettyTerm ctx.dnames ctx.tnames s),
hangDSingle "has type" !(prettyTerm ctx.dnames ctx.tnames a), hangDSingle "has type" !(prettyTerm ctx.dnames ctx.tnames a),
hangDSingle "with quantity" !(prettyQty sg.qty)]) hangDSingle "with quantity" !(prettyQty sg.qty)])
(prettyErrorNoLoc showContext err)|] (prettyErrorNoLoc err)|]
WhileCheckingTy ctx a k err => WhileCheckingTy ctx a k err =>
[|vappendBlank [|vappendBlank
(inTContext ctx . sep =<< sequence (inTContext ctx . sep =<< sequence
[hangDSingle "while checking" !(prettyTerm ctx.dnames ctx.tnames a), [hangDSingle "while checking" !(prettyTerm ctx.dnames ctx.tnames a),
pure $ text $ isTypeInUniverse k]) pure $ text $ isTypeInUniverse k])
(prettyErrorNoLoc showContext err)|] (prettyErrorNoLoc err)|]
WhileInferring ctx sg e err => WhileInferring ctx sg e err =>
[|vappendBlank [|vappendBlank
@ -363,7 +381,7 @@ prettyErrorNoLoc showContext = \case
[hangDSingle "while inferring the type of" [hangDSingle "while inferring the type of"
!(prettyElim ctx.dnames ctx.tnames e), !(prettyElim ctx.dnames ctx.tnames e),
hangDSingle "with quantity" !(prettyQty sg.qty)]) hangDSingle "with quantity" !(prettyQty sg.qty)])
(prettyErrorNoLoc showContext err)|] (prettyErrorNoLoc err)|]
WhileComparingT ctx mode sg a s t err => WhileComparingT ctx mode sg a s t err =>
[|vappendBlank [|vappendBlank
@ -373,7 +391,7 @@ prettyErrorNoLoc showContext = \case
!(prettyTerm [<] ctx.tnames t), !(prettyTerm [<] ctx.tnames t),
hangDSingle "at type" !(prettyTerm [<] ctx.tnames a), hangDSingle "at type" !(prettyTerm [<] ctx.tnames a),
hangDSingle "with quantity" !(prettyQty sg.qty)]) hangDSingle "with quantity" !(prettyQty sg.qty)])
(prettyErrorNoLoc showContext err)|] (prettyErrorNoLoc err)|]
WhileComparingE ctx mode sg e f err => WhileComparingE ctx mode sg e f err =>
[|vappendBlank [|vappendBlank
@ -382,26 +400,13 @@ prettyErrorNoLoc showContext = \case
hangDSingle (text "is \{prettyMode mode}") hangDSingle (text "is \{prettyMode mode}")
!(prettyElim [<] ctx.tnames f), !(prettyElim [<] ctx.tnames f),
hangDSingle "with quantity" !(prettyQty sg.qty)]) hangDSingle "with quantity" !(prettyQty sg.qty)])
(prettyErrorNoLoc showContext err)|] (prettyErrorNoLoc err)|]
where where
vappendBlank : Doc opts -> Doc opts -> Doc opts vappendBlank : Doc opts -> Doc opts -> Doc opts
vappendBlank a b = flush a `vappend` b vappendBlank a b = flush a `vappend` b
inTContext : TyContext d n -> Doc opts -> Eff Pretty (Doc opts) export
inTContext ctx doc = prettyError : Error -> Eff Pretty (Doc opts)
if showContext && not (null ctx) then prettyError err = sep <$> sequence
pure $ vappend doc (sep ["in context", !(prettyTyContext ctx)]) [prettyLoc err.loc, indentD =<< prettyErrorNoLoc err]
else pure doc
inEContext : EqContext n -> Doc opts -> Eff Pretty (Doc opts)
inEContext ctx doc =
if showContext && not (null ctx) then
pure $ vappend doc (sep ["in context", !(prettyEqContext ctx)])
else pure doc
export
prettyError : {opts : _} -> (showContext : Bool) ->
Error -> Eff Pretty (Doc opts)
prettyError showContext err = sep <$> sequence
[prettyLoc err.loc, indentD =<< prettyErrorNoLoc showContext err]