1
{- arch-tag: ConfigParser types
2
Copyright (C) 2004-2005 John Goerzen <jgoerzen@complete.org>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU Lesser General Public License as published by
6
the Free Software Foundation; either version 2.1 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
Module : Data.ConfigFile.Types
21
Copyright : Copyright (C) 2004-2005 John Goerzen
22
License : GNU LGPL, version 2.1 or above
24
Maintainer : John Goerzen <jgoerzen@complete.org>
25
Stability : provisional
28
Internal types for "Data.ConfigFile". This module is not intended to be
29
used directly by your programs.
31
Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
34
module Data.ConfigFile.Types (
36
CPErrorData(..), CPError, {-CPResult,-}
42
import qualified Data.Map as Map
44
import Control.Monad.Error
46
{- | Internal output from parser -}
47
type ParseOutput = [(String, [(String, String)])]
49
{- | Names of sections -}
50
type SectionSpec = String
52
{- | Names of options -}
53
type OptionSpec = String
55
{- | Storage of options. -}
56
type CPOptions = Map.Map OptionSpec String
58
{- | The main data storage type (storage of sections).
60
PLEASE NOTE: This type is exported only for use by other modules under
61
Data.ConfigFile. You should NEVER access the FiniteMap in a ConfigParser
62
directly. This type may change in future releases of MissingH, which could
63
break your programs. Please retrict yourself to the interface in
66
type CPData = Map.Map SectionSpec CPOptions
68
{- | Possible ConfigParser errors. -}
69
data CPErrorData = ParseError String -- ^ Parse error
70
| SectionAlreadyExists SectionSpec -- ^ Attempt to create an already-existing ection
71
| NoSection SectionSpec -- ^ The section does not exist
72
| NoOption OptionSpec -- ^ The option does not exist
73
| OtherProblem String -- ^ Miscellaneous error
74
| InterpolationError String -- ^ Raised by 'Data.ConfigFile.interpolatingAccess' if a request was made for a non-existant option
75
deriving (Eq, Ord, Show)
77
{- | Indicates an error occurred. The String is an explanation of the location
79
type CPError = (CPErrorData, String)
81
instance Error CPError where
82
noMsg = (OtherProblem "", "")
83
strMsg x = (OtherProblem x, "")
85
{- Removed due to Hugs incompatibility.
87
| Basic ConfigParser error handling. The Left value indicates
88
an error, while a Right value indicates success.
89
type CPResult a = MonadError CPError m => m a
92
{- | This is the main record that is used by 'Data.ConfigFile'.
94
data ConfigParser = ConfigParser
95
{ -- | The data itself
97
-- | How to transform an option into a standard representation
98
optionxform :: (OptionSpec -> OptionSpec),
99
-- | Function to look up an option, considering a default value
100
-- if 'usedefault' is True; or ignoring a default value otherwise.
101
-- The option specification is assumed to be already transformed.
102
defaulthandler :: ConfigParser -> SectionSpec -> OptionSpec -> Either CPError String,
103
-- | Whether or not to seek out a default action when no match
106
-- | Function that is used to perform lookups, do optional
107
-- interpolation, etc. It is assumed that accessfunc
108
-- will internally call defaulthandler to do the underlying lookup.
109
-- The option value is not assumed to be transformed.
110
accessfunc :: (ConfigParser -> SectionSpec -> OptionSpec -> Either CPError String)