perga/lib/Errors.hs

38 lines
1.3 KiB
Haskell
Raw Normal View History

2024-11-17 18:33:14 -08:00
module Errors where
import Expr
2024-12-08 12:40:52 -08:00
import Prettyprinter
import Prettyprinter.Render.Text
import Prelude hiding (group)
2024-11-17 18:33:14 -08:00
data Error
= UnboundVariable Text
2024-12-08 12:40:52 -08:00
| NotASort Expr
2024-11-17 18:33:14 -08:00
| ExpectedPiType Expr Expr
| NotEquivalent Expr Expr Expr
2024-11-20 07:37:49 -08:00
| PNMissingType Text
| DuplicateDefinition Text
2024-11-17 18:33:14 -08:00
deriving (Eq, Ord)
2024-12-08 12:40:52 -08:00
instance Pretty Error where
pretty (UnboundVariable x) = "Unbound variable: '" <> pretty x <> "'"
pretty (NotASort x) = group $ hang 4 ("Term:" <> line <> pretty x) <> line <> "is not a type"
2024-12-08 17:40:37 -08:00
pretty (ExpectedPiType x t) = group $ hang 4 ("Term:" <> line <> pretty x) <> line <> hang 4 ("is not a function, instead is type" <> line <> pretty t)
2024-12-08 12:40:52 -08:00
pretty (NotEquivalent a a' e) =
group $
hang 4 ("Cannot unify" <> line <> pretty a)
<> line
<> hang 4 ("with" <> line <> pretty a')
<> line
<> hang 4 ("when evaluating" <> line <> pretty e)
pretty (PNMissingType x) = "Axiom '" <> pretty x <> "' missing type ascription"
pretty (DuplicateDefinition n) = "'" <> pretty n <> "' already defined"
2024-11-22 19:44:31 -08:00
instance ToText Error where
2024-12-08 12:40:52 -08:00
toText = renderStrict . layoutSmart (LayoutOptions (AvailablePerLine 100 1.0)) . pretty
2024-11-22 19:44:31 -08:00
instance ToString Error where
toString = toString . toText
2024-11-17 18:33:14 -08:00
type Result = Either Error