diff --git a/src/Language/Cimple.hs b/src/Language/Cimple.hs index ca3e484..8d315bf 100644 --- a/src/Language/Cimple.hs +++ b/src/Language/Cimple.hs @@ -2,9 +2,12 @@ module Language.Cimple ( module X , AstActions , defaultActions + , AstActions' + , defaultActions' ) where import Control.Monad.State.Lazy (State) +import qualified Control.Monad.State.Strict as SState import Data.Text (Text) import Language.Cimple.Annot as X @@ -18,3 +21,8 @@ type AstActions a = X.IdentityActions (State a) Text defaultActions :: AstActions state defaultActions = X.identityActions + +type AstActions' a = X.IdentityActions (SState.State a) Text + +defaultActions' :: AstActions' state +defaultActions' = X.identityActions diff --git a/src/Language/Cimple/Diagnostics.hs b/src/Language/Cimple/Diagnostics.hs index ab4fee2..a8c9274 100644 --- a/src/Language/Cimple/Diagnostics.hs +++ b/src/Language/Cimple/Diagnostics.hs @@ -3,19 +3,22 @@ {-# LANGUAGE StrictData #-} module Language.Cimple.Diagnostics ( Diagnostics + , Diagnostics' , HasDiagnostics (..) , warn + , warn' , sloc ) where -import Control.Monad.State.Lazy (State) -import qualified Control.Monad.State.Lazy as State -import Data.Fix (foldFix) -import Data.Text (Text) -import qualified Data.Text as Text -import Language.Cimple.Ast (Node) -import qualified Language.Cimple.Flatten as Flatten -import Language.Cimple.Lexer (Lexeme (..), lexemeLine) +import Control.Monad.State.Lazy (State) +import qualified Control.Monad.State.Lazy as State +import qualified Control.Monad.State.Strict as SState +import Data.Fix (foldFix) +import Data.Text (Text) +import qualified Data.Text as Text +import Language.Cimple.Ast (Node) +import qualified Language.Cimple.Flatten as Flatten +import Language.Cimple.Lexer (Lexeme (..), lexemeLine) type DiagnosticsT diags a = State diags a type Diagnostics a = DiagnosticsT [Text] a @@ -25,6 +28,14 @@ warn => FilePath -> at -> Text -> DiagnosticsT diags () warn file l w = State.modify (addDiagnostic $ sloc file l <> ": " <> w) +type DiagnosticsT' diags a = SState.State diags a +type Diagnostics' a = DiagnosticsT' [Text] a + +warn' + :: (HasLocation at, HasDiagnostics diags) + => FilePath -> at -> Text -> DiagnosticsT' diags () +warn' file l w = SState.modify (addDiagnostic $ sloc file l <> ": " <> w) + class HasDiagnostics a where addDiagnostic :: Text -> a -> a