module DDC.Source.Tetra.Transform.Defix.Error
(Error (..))
where
import DDC.Source.Tetra.Exp
import DDC.Base.Pretty
import qualified DDC.Data.SourcePos as BP
data Error a n
= ErrorNoInfixDef
{ errorAnnot :: a
, errorSymbol :: String }
| ErrorDefixNonAssoc
{ errorOp1 :: String
, errorAnnot1 :: a
, errorOp2 :: String
, errorAnnot2 :: a }
| ErrorDefixMixedAssoc
{ errorAnnot :: a
, errorOps :: [String] }
| ErrorMalformed
{ errorAnnot :: a
, errorExp :: Exp a n }
deriving Show
instance (Pretty n)
=> Pretty (Error BP.SourcePos n) where
ppr err
= case err of
ErrorNoInfixDef{}
-> vcat [ ppr $ errorAnnot err
, text "No infix definition for symbol: " <> ppr (errorSymbol err) ]
ErrorDefixNonAssoc{}
-> vcat [ ppr $ errorAnnot1 err
, text "Ambiguous infix expression."
, text " Operator '" <> text (errorOp1 err)
<> text "' at " <> ppr (errorAnnot1 err)
<+> text "is non associative,"
, text " but the same precedence as"
, text " operator '" <> text (errorOp2 err)
<> text "' at " <> ppr (errorAnnot2 err)
<> text "."]
ErrorDefixMixedAssoc{}
-> vcat [ ppr $ errorAnnot err
, text "Ambiguous infix expression."
, text " operators " <> hsep (map ppr (errorOps err))
<> text "have different associativities but same precedence." ]
ErrorMalformed{}
-> vcat [ ppr $ errorAnnot err
, text "Malformed infix expression." ]