[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:47:57 UTC 2010


The following commit has been merged in the master branch:
commit 867ecdd6636a8d63b77a0aa6930a1d725ab1a12c
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sat Nov 20 02:16:37 2004 +0100

    Added basic ConfigParser types
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-101)

diff --git a/ChangeLog b/ChangeLog
index 46d355a..1fe6a9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,21 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-19 19:16:37 GMT	John Goerzen <jgoerzen at complete.org>	patch-101
+
+    Summary:
+      Added basic ConfigParser types
+    Revision:
+      missingh--head--0.5--patch-101
+
+
+    new files:
+     libsrc/MissingH/ConfigParser/Types.hs
+
+    modified files:
+     ChangeLog testsrc/ConfigParser/Parsertest.hs
+
+
 2004-11-19 15:36:53 GMT	John Goerzen <jgoerzen at complete.org>	patch-100
 
     Summary:
diff --git a/libsrc/MissingH/ConfigParser/Types.hs b/libsrc/MissingH/ConfigParser/Types.hs
new file mode 100644
index 0000000..5e04e96
--- /dev/null
+++ b/libsrc/MissingH/ConfigParser/Types.hs
@@ -0,0 +1,83 @@
+{- arch-tag: ConfigParser types
+Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+
+{- |
+   Module     : MissingH.ConfigParser.Types
+   Copyright  : Copyright (C) 2004 John Goerzen
+   License    : GNU GPL, version 2 or above
+
+   Maintainer : John Goerzen, 
+   Maintainer : jgoerzen at complete.org
+   Stability  : provisional
+   Portability: portable
+
+Internal types for "MissingH.ConfigParser".  This module is not intended to be
+used directly by your programs.
+
+Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
+-}
+
+module MissingH.ConfigParser.Types (
+                                    CPOptions, CPData, 
+                                    ConfigParser(..), empty,
+                                    fromAL
+                                   ) where
+import Data.FiniteMap
+import Data.Char
+import MissingH.ConfigParser.Parser
+
+{- | Storage of options. -}
+type CPOptions = FiniteMap String String
+
+{- | The main data storage type (storage of sections). -}
+type CPData = FiniteMap String CPOptions
+
+{- | This is the main record that is used by 'MissingH.ConfigParser'.
+-}
+data ConfigParser = ConfigParser 
+    { -- | The data itself
+      content :: CPData,
+      -- | How to transform an option into a standard representation
+      optionxform :: (String -> String),
+      --defaulthandler :: (ConfigParser -> String -> String),
+      -- | Whether or not to seek out a default action when no match
+      -- is found.
+      usedefault :: Bool
+    }
+
+{- | The default empty 'MissingH.ConfigParser' object.
+
+The content contains only an empty mandatory @DEFAULT@ section.
+
+ at optionxform@ is set to @map toLower at .
+
+ at usedefault@ is set to @True at .
+-}
+empty = ConfigParser { content = fromAL [("DEFAULT", [])],
+                       optionxform = map toLower,
+                       usedefault = True}
+
+{- | Low-level tool to convert a parsed object into a 'CPData'
+representation.  Performs no option conversions or special handling
+of @DEFAULT at . -}
+fromAL :: ParseOutput -> CPData
+fromAL origal =
+    let conv :: CPData -> (String, [(String, String)]) -> CPData
+        conv fm sect = addToFM fm (fst sect) (listToFM $ snd sect)
+        in
+        foldl conv emptyFM origal
diff --git a/testsrc/ConfigParser/Parsertest.hs b/testsrc/ConfigParser/Parsertest.hs
index bc3d01c..37ffc1c 100644
--- a/testsrc/ConfigParser/Parsertest.hs
+++ b/testsrc/ConfigParser/Parsertest.hs
@@ -57,10 +57,10 @@ test_basic =
 
 test_asserts =
         do
-        {-
+
         assertRaises "e test1" (ErrorCall "Lexer: \"(string)\" (line 1, column 5):\nunexpected \"\\n\"\nexpecting Option separator")
                       ([] @=? parse_string "#foo\nthis is bad data")
-        -}
+
         assertRaises "e test2" (ErrorCall "Lexer: \"(string)\" (line 2, column 9):\nunexpected \"\\n\"\nexpecting Option separator")
                      ([] @=? parse_string "[sect1]\n#iiiiii \n  extensionline\n#foo")
 

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list