haskell-scfg

[MIRROR] Haskell library for scfg

git clone git://git.marius.pm/haskell-scfg.git

 1{-# LANGUAGE InstanceSigs #-}
 2
 3-- | Core types for the scfg configuration file format.
 4module Data.Scfg.Types (
 5  Directive (..),
 6  Config,
 7  ParseError (..),
 8) where
 9
10import Control.Exception (Exception (..))
11import Data.Text (Text)
12import qualified Data.Text as T
13
14{- | A directive: a name, zero or more parameteres, and zero or more
15child directives.
16-}
17data Directive = Directive
18  { directiveName :: Text
19  , directiveParams :: [Text]
20  , directiveChildren :: [Directive]
21  }
22  deriving (Show, Eq)
23
24-- | A parsed scfg configuration: a list of top-level directives.
25type Config = [Directive]
26
27-- | An error that occurred while parsing a scfg configuration.
28data ParseError = ParseError
29  { errorLine :: Int
30  -- ^ Line number of parse error
31  , errorColumn :: Int
32  -- ^ Column number of parse error
33  , errorMessage :: Text
34  -- ^ Human-readable error message describing the parse error
35  }
36  deriving (Show, Eq)
37
38instance Exception ParseError where
39  displayException :: ParseError -> String
40  displayException = T.unpack . errorMessage