[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:48:34 UTC 2010


The following commit has been merged in the master branch:
commit ff6855c54b358f50add8d621220ac140e7e84154
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Nov 30 03:00:23 2004 +0100

    Converted error types
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-116)

diff --git a/ChangeLog b/ChangeLog
index 71bd33c..972ca17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-29 20:00:23 GMT	John Goerzen <jgoerzen at complete.org>	patch-116
+
+    Summary:
+      Converted error types
+    Revision:
+      missingh--head--0.5--patch-116
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/ConfigParser.hs
+     libsrc/MissingH/ConfigParser/Parser.hs
+     libsrc/MissingH/ConfigParser/Types.hs
+
+
 2004-11-29 18:47:31 GMT	John Goerzen <jgoerzen at complete.org>	patch-115
 
     Summary:
diff --git a/libsrc/MissingH/ConfigParser.hs b/libsrc/MissingH/ConfigParser.hs
index 03aa169..d410ad8 100644
--- a/libsrc/MissingH/ConfigParser.hs
+++ b/libsrc/MissingH/ConfigParser.hs
@@ -108,31 +108,37 @@ new data taking precedence over the old.  However, unlike
 as set in the old object are preserved since the on-disk representation
 does not convey those options.
 
-May raise an exception on a syntax error or if the file could not be
-accessed.
+May return an error if there is a syntax error.  May raise an exception if the file could not be accessed.
 -}
-readfile :: ConfigParser -> FilePath -> IO (CPResult ConfigParser)
+readfile :: ConfigParser -> FilePath ->IO (CPResult ConfigParser)
+{-
 readfile cp fp = do n <- parse_file fp
-                    return $ readutil cp n
+                    return $ do y <- n
+                                return $ readutil cp y
+-}
+readfile cp fp = do n <- parse_file fp
+                    return $ n >>= (return . (readutil cp))
 
 {- | Like 'readfile', but uses an already-open handle.  You should
 use 'readfile' instead of this if possible, since it will be able to
 generate better error messages.
 
-May raise an exception on a syntax error.
+Errors would be returned on a syntax error.
 -}
 readhandle :: ConfigParser -> Handle -> IO (CPResult ConfigParser)
 readhandle cp h = do n <- parse_handle h
-                     return $ readutil cp n
+                     return $ n >>= (return . (readutil cp))
 
 {- | Like 'readfile', but uses a string.  You should use 'readfile'
 instead of this if you are processing a file, since it can generate
 better error messages.
 
-May raise an exception on a syntax error.
+Errors would be returned on a syntax error.
 -}
 readstring :: ConfigParser -> String -> CPResult ConfigParser
-readstring cp s = readutil cp $ parse_string s
+readstring cp s = do
+                  n <- parse_string s
+                  return $ readutil cp n
 
 {- | Returns a list of sections in your configuration file.  Never includes
 the always-present section @DEFAULT at . -}
@@ -151,7 +157,7 @@ section was already present.  Otherwise, returns the new
 add_section :: ConfigParser -> SectionSpec -> CPResult ConfigParser
 add_section cp s =
     if has_section cp s
-       then throwError $ SectionAlreadyExists ("add_section: section " ++ s ++ " already exists")
+       then throwError $ (SectionAlreadyExists s, "add_section")
        else return $ cp {content = addToFM (content cp) s emptyFM}
 
 {- | Returns a list of the names of all the options present in the
@@ -160,7 +166,7 @@ given section.
 Returns an error if the given section does not exist.
 -}
 options :: ConfigParser -> SectionSpec -> CPResult [OptionSpec]
-options cp x = maybeToEither (NoSection x) $ 
+options cp x = maybeToEither (NoSection x, "options") $ 
                do
                o <- lookupFM (content cp) x
                return $ keysFM o
@@ -210,13 +216,13 @@ getbool cp s o =
                   "no" -> return False
                   "off" -> return False
                   "disabled" -> return False
-                  _ -> throwError (ParseError $ "getbool: couldn't parse " ++
-                                   val ++ " from " ++ s ++ "/" ++ o)
+                  _ -> throwError (ParseError $ "couldn't parse bool " ++
+                                   val ++ " from " ++ s ++ "/" ++ o, "getbool")
 
 {- | Returns a list of @(optionname, value)@ pairs representing the content
 of the given section.  Returns an error the section is invalid. -}
 items :: ConfigParser -> SectionSpec -> CPResult [(OptionSpec, String)]
-items cp s = do fm <- maybeToEither (NoSection s) $ lookupFM (content cp) s
+items cp s = do fm <- maybeToEither (NoSection s, "items") $ lookupFM (content cp) s
                 return $ fmToList fm
 
 {- | Sets the option to a new value, replacing an existing one if it exists.
@@ -224,7 +230,7 @@ items cp s = do fm <- maybeToEither (NoSection s) $ lookupFM (content cp) s
 Returns an error if the section does not exist. -}
 set :: ConfigParser -> SectionSpec -> OptionSpec -> String -> CPResult ConfigParser
 set cp s passedo val = 
-    do sectmap <- maybeToEither (NoSection s) $ lookupFM (content cp) s
+    do sectmap <- maybeToEither (NoSection s, "set") $ lookupFM (content cp) s
        let o = (optionxform cp) passedo
        let newsect = addToFM sectmap o val
        let newmap = addToFM (content cp) s newsect
diff --git a/libsrc/MissingH/ConfigParser/Parser.hs b/libsrc/MissingH/ConfigParser/Parser.hs
index 457e513..e5532c0 100644
--- a/libsrc/MissingH/ConfigParser/Parser.hs
+++ b/libsrc/MissingH/ConfigParser/Parser.hs
@@ -67,10 +67,10 @@ parse_handle h =
 -- Private funcs
 ----------------------------------------------------------------------
 detokenize fp l =
-    let conv msg (Left err) = Left $ (ParseError $ msg ++ (show err))
+    let conv msg (Left err) = Left $ (ParseError (msg ++ (show err)), msg)
         conv msg (Right val) = Right val
-        in do r <- conv "Lexer: " l
-              conv "Parser: " $ runParser main () fp r
+        in do r <- conv "lexer" l
+              conv "parser" $ runParser main () fp r
 
 main :: GeneralizedTokenParser CPTok () ParseOutput
 main =
diff --git a/libsrc/MissingH/ConfigParser/Types.hs b/libsrc/MissingH/ConfigParser/Types.hs
index da77dc0..1572de4 100644
--- a/libsrc/MissingH/ConfigParser/Types.hs
+++ b/libsrc/MissingH/ConfigParser/Types.hs
@@ -68,8 +68,11 @@ data CPErrorData = ParseError String        -- ^ Parse error
                  | OtherProblem String      -- ^ Miscellaneous error
                    deriving (Eq, Ord, Show)
 
-{- | Indicates an error occurred. -}
-type CPError = (CPErrorData, String)
+{- | Indicates an error occurred.  The String is an explanation of the location
+of the error. -}
+type CPError = (CPErrorData -- ^ The error itself
+               , String -- ^ Where it occurred
+               )
 
 instance Error CPError where
     noMsg = (OtherProblem "", "")
@@ -123,8 +126,8 @@ defdefaulthandler :: ConfigParser -> SectionSpec -> OptionSpec -> CPResult Strin
 defdefaulthandler cp sect opt = 
     let fm = content cp
         lookup :: SectionSpec -> OptionSpec -> CPResult String
-        lookup s o = do sect <- maybeToEither (NoSection s) $ lookupFM fm s
-                        maybeToEither (NoOption o) $ lookupFM sect o
+        lookup s o = do sect <- maybeToEither (NoSection s, "lookup handler") $ lookupFM fm s
+                        maybeToEither (NoOption o, "lookup handler") $ lookupFM sect o
         trydefault :: CPError -> CPResult String
         trydefault e = if (usedefault cp)
                        then lookup "DEFAULT" opt

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list