Safe Haskell | None |
---|---|
Language | Haskell2010 |
This is in a separate module from the module Language.Clafer so that other modules that require ClaferEnv can just import this module without all the parsingcompilinegenerating functionality.
- data ClaferEnv = ClaferEnv {}
- irModuleTrace :: ClaferEnv -> Map Span [Ir]
- uidIClaferMap :: ClaferEnv -> UIDIClaferMap
- makeEnv :: ClaferArgs -> ClaferEnv
- getAst :: Monad m => ClaferT m Module
- getIr :: Monad m => ClaferT m (IModule, GEnv, Bool)
- type ClaferM = ClaferT Identity
- type ClaferT m = ErrorT ClaferErrs (StateT ClaferEnv m)
- data CErr p
- data CErrs p = ClaferErrs {}
- type ClaferErr = CErr ErrPos
- type ClaferErrs = CErrs ErrPos
- type ClaferSErr = CErr Span
- type ClaferSErrs = CErrs Span
- data ErrPos = ErrPos {}
- data PartialErrPos
- = ErrFragPos { }
- | ErrFragSpan { }
- | ErrModelPos { }
- | ErrModelSpan {
- pModelSpan :: Span
- throwErrs :: (Monad m, Throwable t) => [t] -> ClaferT m a
- throwErr :: (Monad m, Throwable t) => t -> ClaferT m a
- catchErrs :: Monad m => ClaferT m a -> ([ClaferErr] -> ClaferT m a) -> ClaferT m a
- getEnv :: Monad m => ClaferT m ClaferEnv
- getsEnv :: Monad m => (ClaferEnv -> a) -> ClaferT m a
- modifyEnv :: Monad m => (ClaferEnv -> ClaferEnv) -> ClaferT m ()
- putEnv :: Monad m => ClaferEnv -> ClaferT m ()
- runClafer :: ClaferArgs -> ClaferM a -> Either [ClaferErr] a
- runClaferT :: Monad m => ClaferArgs -> ClaferT m a -> m (Either [ClaferErr] a)
- class Throwable t where
- data Span = Span Pos Pos
- data Pos = Pos Integer Integer
Documentation
irModuleTrace :: ClaferEnv -> Map Span [Ir] Source
This simulates a field in the ClaferEnv that will always recompute the map, since the IR always changes and the map becomes obsolete
uidIClaferMap :: ClaferEnv -> UIDIClaferMap Source
This simulates a field in the ClaferEnv that will always recompute the map, since the IR always changes and the map becomes obsolete maps from a UID to an IClafer with the given UID
makeEnv :: ClaferArgs -> ClaferEnv Source
Possible errors that can occur when using Clafer | Generate errors using throwErr/throwErrs:
ClaferErr | Generic error |
ParseErr | Error generated by the parser |
SemanticErr | Error generated by semantic analysis |
Clafer keeps track of multiple errors.
type ClaferErrs = CErrs ErrPos Source
type ClaferSErr = CErr Span Source
type ClaferSErrs = CErrs Span Source
data PartialErrPos Source
The full ErrPos requires lots of information that needs to be consistent. Every time we throw an error, | we need BOTH the (fragId, fragPos) AND modelPos. This makes it easier for developers using ClaferT so they | only need to provide part of the information and the rest is automatically calculated. The code using | ClaferT is more concise and less error-prone. | | modelPos <- modelPosFromFragPos fragdId fragPos | throwErr $ ParserErr (ErrPos fragId fragPos modelPos) | | vs | | throwErr $ ParseErr (ErrFragPos fragId fragPos) | | Hopefully making the error handling easier will make it more universal.
ErrFragPos | Position relative to the start of the fragment. Will calculate model position automatically. | fragId starts at 0 | The position is relative to the start of the fragment. |
ErrFragSpan | |
ErrModelPos | Position relative to the start of the complete model. Will calculate fragId and fragPos automatically. | The position is relative to the entire complete model. |
ErrModelSpan | |
|
catchErrs :: Monad m => ClaferT m a -> ([ClaferErr] -> ClaferT m a) -> ClaferT m a Source
Catch errors
putEnv :: Monad m => ClaferEnv -> ClaferT m () Source
Set the ClaferEnv. Remember to set the env after every change.
runClaferT :: Monad m => ClaferArgs -> ClaferT m a -> m (Either [ClaferErr] a) Source
Uses the ErrorT convention: | Left is for error (a string containing the error message) | Right is for success (with the result)