{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE Strict #-} {-# LANGUAGE StrictData #-} module Language.Cimple.Diagnostics ( Diagnostics , HasDiagnostics (..) , warn , sloc ) where import Control.Monad.State.Strict (State) import qualified Control.Monad.State.Strict as State import Data.Text (Text) import Language.Cimple.DescribeAst (HasLocation (..)) type DiagnosticsT diags a = State diags a type Diagnostics a = DiagnosticsT [Text] a warn :: (HasLocation at, HasDiagnostics diags) => FilePath -> at -> Text -> DiagnosticsT diags () warn :: FilePath -> at -> Text -> DiagnosticsT diags () warn FilePath file at l Text w = (diags -> diags) -> DiagnosticsT diags () forall s (m :: * -> *). MonadState s m => (s -> s) -> m () State.modify (Text -> diags -> diags forall a. HasDiagnostics a => Text -> a -> a addDiagnostic (Text -> diags -> diags) -> Text -> diags -> diags forall a b. (a -> b) -> a -> b $ FilePath -> at -> Text forall a. HasLocation a => FilePath -> a -> Text sloc FilePath file at l Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text ": " Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text w) class HasDiagnostics a where addDiagnostic :: Text -> a -> a instance HasDiagnostics [Text] where addDiagnostic :: Text -> [Text] -> [Text] addDiagnostic = (:)