| |||||||||||
| |||||||||||
Description | |||||||||||
This module provides a Monad for an internal state and IO commands. The state consists of two parts, the user state and the system state user state ist a type parameter, the system state is a list name-value pair. If the user state is not needed, the type parameter can be instantiated with (). Furthermore there are types for Xml filter working on this monad and functions for manipulating the state components and for lifting i/o commands and XmlFilter to monad filters. Error reporting functions are also located in this module. Version : $Id: XmlState.hs,v 1.3 20050527 13:15:23 hxml Exp $ | |||||||||||
Synopsis | |||||||||||
Documentation | |||||||||||
data SysState | |||||||||||
| |||||||||||
type SysStateAttrs = AssocList String XmlTrees | |||||||||||
data XmlState state | |||||||||||
| |||||||||||
type XState state res = StateIO (XmlState state) res | |||||||||||
The monad type for commands. It is an instance of StateIO from the general module Control.Monad.MonadStateIO. | |||||||||||
type XmlStateFilter state = XmlTree -> XState state XmlTrees | |||||||||||
The XmlFilter type for filters working on a state | |||||||||||
changeState :: (state -> state) -> XState state state | |||||||||||
change the user state
| |||||||||||
setState :: state -> XState state state | |||||||||||
set the user state.
| |||||||||||
getState :: XState state state | |||||||||||
read the user state
| |||||||||||
changeSysState :: (SysState -> SysState) -> XState state SysState | |||||||||||
change the system part of the state. see also : changeState | |||||||||||
setSysState :: SysState -> XState state SysState | |||||||||||
set the system part of the state. see also : setState | |||||||||||
getSysState :: XState state SysState | |||||||||||
read the system part of the state. see also : getState | |||||||||||
initialSysState :: SysState | |||||||||||
the initial system state an empty list of attribute value pairs | |||||||||||
changeSysStateAttrs :: (SysStateAttrs -> SysStateAttrs) -> SysState -> SysState | |||||||||||
change the attributes in the system state | |||||||||||
setSysErrorHandler :: XmlStateFilter () -> XState state () | |||||||||||
set the error message handler | |||||||||||
getSysErrorHandler :: XState state (XmlStateFilter ()) | |||||||||||
get the error handler | |||||||||||
setSysParamTree :: String -> XmlTrees -> XState state () | |||||||||||
set or change a single system parameter.
see also : setSysParam, setSysParamInt | |||||||||||
setSysParam :: String -> String -> XState state () | |||||||||||
set or change a single system parameter of type string.
see also : setSysParamTree, setSysParamInt | |||||||||||
setSysParamInt :: String -> Int -> XState state () | |||||||||||
set or change a single integer type system parameter see also : setSysParam | |||||||||||
setSystemParams :: XmlStateFilter state | |||||||||||
add (or change) all attributes of the document root to the system state - returns : this | |||||||||||
getSysParamTree :: String -> XState state XmlTrees | |||||||||||
read a system parameter
| |||||||||||
getSysParam :: String -> XState state String | |||||||||||
read a system string parameter
| |||||||||||
getSysParamWithDefault :: String -> String -> XState state String | |||||||||||
read a system parameter or return a default value
| |||||||||||
getSysParamInt :: String -> Int -> XState state Int | |||||||||||
read an integer system parameter
see also : getSysParamWithDefault | |||||||||||
run0 :: XmlState state -> XState state res -> IO (res, XmlState state) | |||||||||||
exec a XState command with initial state.
| |||||||||||
run :: state -> XState state res -> IO res | |||||||||||
exec a XState command with initial user state. ignore final user state. like run0, but ignore the resulting user state | |||||||||||
run' :: XState () res -> IO res | |||||||||||
exec a XState command in th IO monad. like run with the empty state (). | |||||||||||
chain' :: state1 -> XState state1 res -> XState state0 (res, state1) | |||||||||||
run a command in a new user state. chain the system state part, init new system state with the current one, run the command and update the old system state with the resulting new system state
| |||||||||||
chain :: state1 -> XState state1 res -> XState state0 res | |||||||||||
like chain' but forget the final user state
| |||||||||||
liftF :: XmlFilter -> XmlStateFilter state | |||||||||||
lift a XmlFilter to a XmlStateFilter filter issue all error nodes as error messages and remove the error nodes from the result
all errors are filtered from the result and issued on stderr | |||||||||||
io :: IO a -> XState state a | |||||||||||
lift an I/O command
| |||||||||||
setTraceLevel :: Int -> XState state () | |||||||||||
set the trace level. convention: 0: no trace output (default) 1: trace important computation steps, e.g. accessing a document 2: trace small computation steps 3: output an intermediate result XmlTree in XML source format 4: output an intermediate result XmlTree in tree representation
| |||||||||||
getTraceLevel :: XState state Int | |||||||||||
get the current trace level.
| |||||||||||
traceCmd :: Int -> XState state a -> XState state () | |||||||||||
trace output for arbitray commands.
| |||||||||||
trace :: Int -> String -> XState state () | |||||||||||
trace output function for simple text.
| |||||||||||
traceState :: Int -> (state -> String) -> XState state () | |||||||||||
trace output of the user part of the program state.
| |||||||||||
clearStatus :: XmlStateFilter state | |||||||||||
filter to reset the state attribute a_status - returns : this | |||||||||||
issueError :: XmlStateFilter state | |||||||||||
report an error message.
see also : issueErr | |||||||||||
errorMsgHandler :: XmlStateFilter state | |||||||||||
setErrorMsgLevel :: XmlStateFilter state | |||||||||||
set the error level in system state | |||||||||||
errorMsgToStderr :: XmlStateFilter state | |||||||||||
default error handler for writing errors to stderr | |||||||||||
errorMsgLogging :: XmlStateFilter state | |||||||||||
error message handler for collecting all error messages all messages are stored under attribute a_error_log they can be read with getSysParamTree a_error_log or by applying the filter getErrorMsg to the root node | |||||||||||
errorMsgLoggingAndToStderr :: XmlStateFilter state | |||||||||||
getErrorMsg :: XmlStateFilter state | |||||||||||
the filter for reading all collected error mesages result is the list of error messages, the input tree is ignored | |||||||||||
errClass :: Int -> String | |||||||||||
error level translation c_warn (1) : warning, c_err (2): error (e.g. parse error, validation error, ...), c_fatal (3) : fatal error (document access error, internal error, ...) | |||||||||||
issueWarn :: String -> XmlStateFilter state | |||||||||||
short cut for issuing a warning see also : issueError, issueErr | |||||||||||
issueErr :: String -> XmlStateFilter state | |||||||||||
short cut for issuing an error see also : issueError | |||||||||||
issueFatal :: String -> XmlStateFilter state | |||||||||||
short cut for issuing a fatal error see also : issueError, issueErr | |||||||||||
addFatal :: String -> XmlStateFilter state | |||||||||||
checkStatus :: XmlStateFilter state | |||||||||||
checks the value of the attribute a_status in a document root. if it contains a value greater or equal to c_err, an error with error message stored in attribute a_module is issued and the filter acts as the noneM filter else its the thisM filter | |||||||||||
setStatus :: Int -> String -> XmlFilter | |||||||||||
add the error level and the module where the error occured to the attributes of a document root node and remove the children when level is greater or equal to c_err | |||||||||||
statusOk :: XmlFilter | |||||||||||
check whether tree is a document root and the status attribute has a value less than c_err | |||||||||||
checkResult :: String -> XmlStateFilter state | |||||||||||
check whether the error level attribute in the system state is set to error, in this case the children of the document root are removed and error info is added as attributes with setStatus else nothing is changed | |||||||||||
processAttrM :: XmlStateFilter a -> XmlStateFilter a | |||||||||||
monadic filter for processing the attribute list of a tag. for other trees this filter acts like noneM see also : processAttr, processAttrl | |||||||||||
Produced by Haddock version 0.7 |