scmdoc

Automatically generate documentation from comments in R7RS Scheme code

git clone https://git.8pit.net/scmdoc.git

 1-- | Data types used for error handling in SchemeDoc.
 2module SchemeDoc.Error where
 3
 4import Control.Exception
 5import qualified Text.ParserCombinators.Parsec as P
 6
 7import SchemeDoc.Types
 8
 9-- | A syntax error occuring during further processing of a S-expression
10-- with a 'SchemeDoc.Format.Formatter'. Currently, only used by the
11-- 'SchemeDoc.Format.Library' 'SchemeDoc.Format.Formatter'.
12data SyntaxError
13    = SyntaxError
14        Sexp
15        -- ^ The S-expression for which an errror occured.
16        String
17        -- ^ A human-readable description of the error.
18    deriving (Show, Eq)
19
20-- | Helper function for creating a new syntax error for a
21-- given S-expression with a given error message.
22makeErr :: Sexp -> String -> Either SyntaxError a
23makeErr expr msg = Left $ SyntaxError expr msg
24
25------------------------------------------------------------------------
26
27-- | Exception occuring during the processing of a R7RS Scheme input.
28--
29-- Can either be a 'ErrParser' (occuring during inital parsing of
30-- the input) or a 'ErrSyntax' (occuring during further processing of
31-- parsed S-expressions).
32data ExpandException = ErrParser P.ParseError | ErrSyntax SyntaxError
33    deriving (Show)
34
35instance Exception ExpandException
36
37-- | Helper function to throw a 'SyntaxError'.
38throwSyntax :: Sexp -> String -> IO a
39throwSyntax e m = throwIO $ ErrSyntax (SyntaxError e m)