[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 0d29099142de354052157aeef708efd223a4bca1
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Nov 30 01:47:31 2004 +0100

    Checkpointing
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-115)

diff --git a/ChangeLog b/ChangeLog
index 4158fa8..71bd33c 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 18:47:31 GMT	John Goerzen <jgoerzen at complete.org>	patch-115
+
+    Summary:
+      Checkpointing
+    Revision:
+      missingh--head--0.5--patch-115
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/ConfigParser.hs
+     libsrc/MissingH/ConfigParser/Parser.hs
+     libsrc/MissingH/ConfigParser/Types.hs
+
+
 2004-11-29 17:08:18 GMT	John Goerzen <jgoerzen at complete.org>	patch-114
 
     Summary:
diff --git a/libsrc/MissingH/ConfigParser.hs b/libsrc/MissingH/ConfigParser.hs
index 9858cbf..03aa169 100644
--- a/libsrc/MissingH/ConfigParser.hs
+++ b/libsrc/MissingH/ConfigParser.hs
@@ -111,7 +111,7 @@ does not convey those options.
 May raise an exception on a syntax error or if the file could not be
 accessed.
 -}
-readfile :: ConfigParser -> FilePath -> IO ConfigParser
+readfile :: ConfigParser -> FilePath -> IO (CPResult ConfigParser)
 readfile cp fp = do n <- parse_file fp
                     return $ readutil cp n
 
@@ -121,7 +121,7 @@ generate better error messages.
 
 May raise an exception on a syntax error.
 -}
-readhandle :: ConfigParser -> Handle -> IO ConfigParser
+readhandle :: ConfigParser -> Handle -> IO (CPResult ConfigParser)
 readhandle cp h = do n <- parse_handle h
                      return $ readutil cp n
 
@@ -131,7 +131,7 @@ better error messages.
 
 May raise an exception on a syntax error.
 -}
-readstring :: ConfigParser -> String -> ConfigParser
+readstring :: ConfigParser -> String -> CPResult ConfigParser
 readstring cp s = readutil cp $ parse_string s
 
 {- | Returns a list of sections in your configuration file.  Never includes
diff --git a/libsrc/MissingH/ConfigParser/Parser.hs b/libsrc/MissingH/ConfigParser/Parser.hs
index 4834ee1..457e513 100644
--- a/libsrc/MissingH/ConfigParser/Parser.hs
+++ b/libsrc/MissingH/ConfigParser/Parser.hs
@@ -42,23 +42,22 @@ import MissingH.Str
 import MissingH.ConfigParser.Lexer
 import System.IO(Handle, hGetContents)
 import MissingH.Parsec
-
-type ParseOutput = [(String, [(String, String)])]
+import MissingH.ConfigParser.Types
 
 ----------------------------------------------------------------------
 -- Exported funcs
 ----------------------------------------------------------------------
 
-parse_string :: String -> ParseOutput
+parse_string :: String -> CPResult ParseOutput
 parse_string s = 
     detokenize "(string)" $ parse loken "(string)" s
 
-parse_file :: FilePath -> IO ParseOutput
+parse_file :: FilePath -> IO (CPResult ParseOutput)
 parse_file f =
     do o <- parseFromFile loken f
        return $ detokenize f o
 
-parse_handle :: Handle -> IO ParseOutput
+parse_handle :: Handle -> IO (CPResult ParseOutput)
 parse_handle h =
     do s <- hGetContents h
        let o = parse loken (show h) s
@@ -68,13 +67,10 @@ parse_handle h =
 -- Private funcs
 ----------------------------------------------------------------------
 detokenize fp l =
-    let r = case l of
-                   Left err -> error $ "Lexer: " ++ (show err)
-                   Right reply -> reply
-        in
-        case runParser main () fp r of
-                                    Left err -> error $ "Parser: " ++ (show err)
-                                    Right reply -> reply
+    let conv msg (Left err) = Left $ (ParseError $ msg ++ (show err))
+        conv msg (Right val) = Right val
+        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 351b780..da77dc0 100644
--- a/libsrc/MissingH/ConfigParser/Types.hs
+++ b/libsrc/MissingH/ConfigParser/Types.hs
@@ -34,17 +34,20 @@ Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
 
 module MissingH.ConfigParser.Types (
                                     CPOptions, CPData, 
-                                    CPError(..), CPResult,
+                                    CPErrorData(..), CPError, CPResult,
                                     ConfigParser(..), empty,
                                     fromAL, SectionSpec,
                                     OptionSpec,
+                                    ParseOutput
                                    ) where
 import Data.FiniteMap
 import Data.Char
 import Control.Monad.Error
-import MissingH.ConfigParser.Parser
 import MissingH.Either
 
+{- | Internal output from parser -}
+type ParseOutput = [(String, [(String, String)])]
+
 {- | Names of sections -}
 type SectionSpec = String
 
@@ -58,22 +61,24 @@ type CPOptions = FiniteMap OptionSpec String
 type CPData = FiniteMap SectionSpec CPOptions
 
 {- | Possible ConfigParser errors. -}
-data CPError = ParseError String        -- ^ Parse error
-             | SectionAlreadyExists String -- ^ Attempt to create an already-existing ection
-             | NoSection SectionSpec    -- ^ The section does not exist
-             | NoOption OptionSpec      -- ^ The option does not exist
-             | OtherProblem String      -- ^ Miscellaneous error
-               deriving (Eq, Ord, Show)
+data CPErrorData = ParseError String        -- ^ Parse error
+                 | SectionAlreadyExists String -- ^ Attempt to create an already-existing ection
+                 | NoSection SectionSpec    -- ^ The section does not exist
+                 | NoOption OptionSpec      -- ^ The option does not exist
+                 | OtherProblem String      -- ^ Miscellaneous error
+                   deriving (Eq, Ord, Show)
+
+{- | Indicates an error occurred. -}
+type CPError = (CPErrorData, String)
 
 instance Error CPError where
-    noMsg = OtherProblem ""
-    strMsg x = OtherProblem x
+    noMsg = (OtherProblem "", "")
+    strMsg x = (OtherProblem x, "")
 
 {- | Basic ConfigParser error handling.  The Left value indicates
 an error, while a Right value indicates success. -}
 type CPResult = Either CPError
 
-
 {- | This is the main record that is used by 'MissingH.ConfigParser'.
 -}
 data ConfigParser = ConfigParser 
@@ -125,27 +130,7 @@ defdefaulthandler cp sect opt =
                        then lookup "DEFAULT" opt
                        else Left e
         in
-        case lookup sect opt of
-             Right x -> Right x
-             Left x -> trydefault x
-
-{-       
-defdefaulthandler cp sect opt =
-    let fm = content cp
-        lookup s o =
-            case lookupFM fm s of
-                Nothing -> Nothing
-                Just sect -> case lookupFM sect o of
-                                 Nothing -> Nothing
-                                 Just x -> Just x
-        in
-        case lookup sect opt of
-            Just r -> Just r
-            Nothing -> if (usedefault cp)
-                       then lookup "DEFAULT" opt
-                       else Nothing
--}
-
+        lookup sect opt `catchError` trydefault
 
 {- | Low-level tool to convert a parsed object into a 'CPData'
 representation.  Performs no option conversions or special handling

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list