{-# LANGUAGE UndecidableInstances #-}
module Agda.Unused.Monad.Error
(
Error(..)
, InternalError(..)
, UnexpectedError(..)
, UnsupportedError(..)
, liftLookup
) where
import Agda.Unused.Types.Context
(LookupError(..))
import Agda.Unused.Types.Name
(QName)
import Agda.Unused.Types.Range
(Range, getRange)
import Agda.Interaction.FindFile
(FindError)
import Agda.Syntax.Concrete.Definitions
(DeclarationException)
import Agda.Syntax.Concrete.Fixity
(MonadFixityError(..))
import Agda.Syntax.Parser
(ParseError)
import Control.Monad.Except
(MonadError, throwError)
data Error where
ErrorAmbiguous
:: !Range
-> !QName
-> Error
ErrorCyclic
:: !Range
-> !QName
-> Error
ErrorDeclaration
:: !DeclarationException
-> Error
ErrorFile
:: !FilePath
-> Error
ErrorFind
:: !Range
-> !QName
-> !FindError
-> Error
ErrorFixity
:: !(Maybe Range)
-> Error
ErrorGlobal
:: !Range
-> Error
ErrorInclude
:: Error
ErrorInternal
:: !InternalError
-> Error
ErrorOpen
:: !Range
-> !QName
-> Error
ErrorParse
:: !ParseError
-> Error
ErrorPolarity
:: !(Maybe Range)
-> Error
ErrorRoot
:: !QName
-> !QName
-> Error
ErrorUnsupported
:: !UnsupportedError
-> !Range
-> Error
data InternalError where
ErrorConstructor
:: !Range
-> InternalError
ErrorMacro
:: !Range
-> InternalError
ErrorModuleName
:: !FilePath
-> InternalError
ErrorName
:: !Range
-> InternalError
ErrorRenaming
:: !Range
-> InternalError
ErrorUnexpected
:: !UnexpectedError
-> !Range
-> InternalError
deriving Int -> InternalError -> ShowS
[InternalError] -> ShowS
InternalError -> String
(Int -> InternalError -> ShowS)
-> (InternalError -> String)
-> ([InternalError] -> ShowS)
-> Show InternalError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InternalError] -> ShowS
$cshowList :: [InternalError] -> ShowS
show :: InternalError -> String
$cshow :: InternalError -> String
showsPrec :: Int -> InternalError -> ShowS
$cshowsPrec :: Int -> InternalError -> ShowS
Show
data UnexpectedError where
UnexpectedAbsurd
:: UnexpectedError
UnexpectedAs
:: UnexpectedError
UnexpectedDontCare
:: UnexpectedError
UnexpectedETel
:: UnexpectedError
UnexpectedEllipsis
:: UnexpectedError
UnexpectedEqual
:: UnexpectedError
UnexpectedField
:: UnexpectedError
UnexpectedNiceFunClause
:: UnexpectedError
UnexpectedOpApp
:: UnexpectedError
UnexpectedOpAppP
:: UnexpectedError
deriving Int -> UnexpectedError -> ShowS
[UnexpectedError] -> ShowS
UnexpectedError -> String
(Int -> UnexpectedError -> ShowS)
-> (UnexpectedError -> String)
-> ([UnexpectedError] -> ShowS)
-> Show UnexpectedError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnexpectedError] -> ShowS
$cshowList :: [UnexpectedError] -> ShowS
show :: UnexpectedError -> String
$cshow :: UnexpectedError -> String
showsPrec :: Int -> UnexpectedError -> ShowS
$cshowsPrec :: Int -> UnexpectedError -> ShowS
Show
data UnsupportedError where
UnsupportedMacro
:: UnsupportedError
UnsupportedUnquote
:: UnsupportedError
deriving Int -> UnsupportedError -> ShowS
[UnsupportedError] -> ShowS
UnsupportedError -> String
(Int -> UnsupportedError -> ShowS)
-> (UnsupportedError -> String)
-> ([UnsupportedError] -> ShowS)
-> Show UnsupportedError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnsupportedError] -> ShowS
$cshowList :: [UnsupportedError] -> ShowS
show :: UnsupportedError -> String
$cshow :: UnsupportedError -> String
showsPrec :: Int -> UnsupportedError -> ShowS
$cshowsPrec :: Int -> UnsupportedError -> ShowS
Show
instance (Monad m, MonadError Error m) => MonadFixityError m where
throwMultipleFixityDecls :: [(Name, [Fixity'])] -> m a
throwMultipleFixityDecls []
= Error -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Maybe Range -> Error
ErrorFixity Maybe Range
forall a. Maybe a
Nothing)
throwMultipleFixityDecls ((Name
n, [Fixity']
_) : [(Name, [Fixity'])]
_)
= Error -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Maybe Range -> Error
ErrorFixity (Range -> Maybe Range
forall a. a -> Maybe a
Just (Name -> Range
forall t. HasRange t => t -> Range
getRange Name
n)))
throwMultiplePolarityPragmas :: [Name] -> m a
throwMultiplePolarityPragmas []
= Error -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Maybe Range -> Error
ErrorPolarity Maybe Range
forall a. Maybe a
Nothing)
throwMultiplePolarityPragmas (Name
n : [Name]
_)
= Error -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Maybe Range -> Error
ErrorPolarity (Range -> Maybe Range
forall a. a -> Maybe a
Just (Name -> Range
forall t. HasRange t => t -> Range
getRange Name
n)))
warnUnknownNamesInFixityDecl :: [Name] -> m ()
warnUnknownNamesInFixityDecl [Name]
_
= () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
warnUnknownNamesInPolarityPragmas :: [Name] -> m ()
warnUnknownNamesInPolarityPragmas [Name]
_
= () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
warnUnknownFixityInMixfixDecl :: [Name] -> m ()
warnUnknownFixityInMixfixDecl [Name]
_
= () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
warnPolarityPragmasButNotPostulates :: [Name] -> m ()
warnPolarityPragmasButNotPostulates [Name]
_
= () -> m ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
liftLookup
:: MonadError Error m
=> Range
-> QName
-> Either LookupError a
-> m a
liftLookup :: Range -> QName -> Either LookupError a -> m a
liftLookup Range
r QName
n (Left LookupError
LookupNotFound)
= Error -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Range -> QName -> Error
ErrorOpen Range
r QName
n)
liftLookup Range
r QName
n (Left LookupError
LookupAmbiguous)
= Error -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Range -> QName -> Error
ErrorAmbiguous Range
r QName
n)
liftLookup Range
_ QName
_ (Right a
x)
= a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x