{- |

Error handling for FSMs.

-}

-- Copyright (c) 2009 Andy Gimblett - http://www.cs.swan.ac.uk/~csandy/
-- BSD Licence (see http://www.opensource.org/licenses/bsd-license.php)

{-# LANGUAGE DeriveDataTypeable #-}

module Data.FsmActions.Error (
  FsmError(..),
  ReadFsmMonad
) where

import Control.Exception
import Control.Monad.Error
import Data.Typeable

-- | Errors when reading matrices from strings.
data FsmError = FsmError { 
      -- | Explanatory message
      msg :: String,
      -- | Offending value
      value :: String
    } deriving (Eq, Typeable)

instance Exception FsmError

instance Error FsmError where
    noMsg    = FsmError "FSM error" ""
    strMsg s = FsmError s ""

instance Show FsmError where
    show (FsmError message val) = message ++ " (" ++ val ++ ")"

-- | Error monad for reading FSMs in.
type ReadFsmMonad = Either FsmError