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


The following commit has been merged in the master branch:
commit 080b18912c0c17884310bd5ca0ecf1fa7c19c025
Author: John Goerzen <jgoerzen at complete.org>
Date:   Wed Dec 1 23:09:58 2004 +0100

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

diff --git a/ChangeLog b/ChangeLog
index ad3d748..8672878 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,22 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-12-01 16:09:58 GMT	John Goerzen <jgoerzen at complete.org>	patch-136
+
+    Summary:
+      Checkpointing again
+    Revision:
+      missingh--head--0.5--patch-136
+
+
+    removed files:
+     cpexample1.hs
+
+    modified files:
+     ChangeLog TODO libsrc/MissingH/ConfigParser.hs
+     libsrc/MissingH/ConfigParser/Types.hs
+
+
 2004-11-30 22:21:19 GMT	John Goerzen <jgoerzen at complete.org>	patch-135
 
     Summary:
diff --git a/TODO b/TODO
index 866b03c..830e379 100644
--- a/TODO
+++ b/TODO
@@ -8,6 +8,7 @@ test configparser:
  * according to ocaml spec
  * with various default options
  * exception system
+ * remove_*
 
 document configparser
 
diff --git a/cpexample1.hs b/cpexample1.hs
deleted file mode 100644
index 9972037..0000000
--- a/cpexample1.hs
+++ /dev/null
@@ -1,16 +0,0 @@
--- arch-tag: ConfigParser example 1 to integrate into docs
-import MissingH.ConfigParser
-import Control.Monad.Error
-
-main = do
-          rv <- runErrorT $
-              do
-              cp <- join $ liftIO $ readfile empty "/etc/passwd"
-              let x = cp
-              liftIO $ putStrLn "In the test"
-              nb <- get x "DEFAULT" "nobody"
-              liftIO $ putStrLn nb
-              foo <- get x "DEFAULT" "foo"
-              liftIO $ putStrLn foo
-              return "done"
-          print rv
diff --git a/libsrc/MissingH/ConfigParser.hs b/libsrc/MissingH/ConfigParser.hs
index 5a369f8..79622e6 100644
--- a/libsrc/MissingH/ConfigParser.hs
+++ b/libsrc/MissingH/ConfigParser.hs
@@ -83,20 +83,19 @@ module MissingH.ConfigParser
 
      -- * Accessing Data
      get, getbool, getnum,
+     sections, has_section,
+     options, has_option,
+     items,
 
-     -- * Setting Data
-     set, setshow,
+     -- * Modifying Data
+     set, setshow, remove_option,
+     add_section, remove_section,
+     merge,
 
      -- * Output Data
-     to_string,
+     to_string
 
-     -- * Meta-queries
-     sections, has_section,
-     options, has_option,
-     items,
 
-     -- * Miscellaneous Manipulation
-     add_section, merge
 ) where
 import MissingH.ConfigParser.Types
 import MissingH.ConfigParser.Parser
@@ -255,6 +254,34 @@ add_section cp s =
        then throwError $ (SectionAlreadyExists s, "add_section")
        else return $ cp {content = addToFM (content cp) s emptyFM}
 
+{- | Removes the specified section.  Returns a 'NoSection' error if
+the section does not exist; otherwise, returns the new 'ConfigParser'
+object.
+
+This call may not be used to remove the @DEFAULT@ section.  Attempting to do
+so will always cause a 'NoSection' error.
+ -}
+remove_section :: ConfigParser -> SectionSpec -> CPResult ConfigParser
+remove_section _ "DEFAULT" = throwError $ (NoSection "DEFAULT", "remove_section")
+remove_section cp s = 
+    if has_section cp s
+       then return $ cp {content = delFromFM (content cp) s}
+       else throwError $ (NoSection s, "remove_section")
+
+{- | Removes the specified option.  Returns a 'NoSection' error if the
+section does not exist and a 'NoOption' error if the option does not
+exist.  Otherwise, returns the new 'ConfigParser' object.
+-}
+remove_option :: ConfigParser -> SectionSpec -> OptionSpec -> CPResult ConfigParser
+remove_option cp s passedo =
+    do sectmap <- maybeToEither (NoSection s, "remove_option") $ lookupFM (content cp) s
+       let o = (optionxform cp) passedo
+       let newsect = delFromFM sectmap o
+       let newmap = addToFM (content cp) s newsect
+       if elemFM o sectmap
+          then return $ cp {content = newmap}
+          else throwError $ (NoOption o, "remove_option")
+
 {- | Returns a list of the names of all the options present in the
 given section.
 
@@ -371,7 +398,16 @@ setshow :: Show a => ConfigParser -> SectionSpec -> OptionSpec -> a -> CPResult
 setshow cp s o val = set cp s o (show val)
 
 {- | Converts the 'ConfigParser' to a string representation that could be
-later re-parsed by this module. -}
+later re-parsed by this module or modified by a human.
+
+Note that this does not necessarily re-create a file that was originally
+loaded.  Things may occur in a different order, comments will be removed,
+etc.  The conversion makes an effort to make the result human-editable,
+but it does not make an effort to make the result identical to the original
+input.
+
+The result is, however, guaranteed to parse the same as the original input.
+ -}
 to_string :: ConfigParser -> String
 to_string cp = 
     let gen_option (key, value) = 
@@ -512,6 +548,10 @@ automatically stripped.
 
 Blank lines or lines consisting solely of whitespace are ignored. 
 
+A line giving an option or a section name may not begin with white space.
+This requirement is necessary so there is no ambiguity between such lines
+and continuation lines for multi-line options.
+
 -}
 
 {- $comments
@@ -687,7 +727,15 @@ It all works quite easily.
 
 {- $configuringcp
 
-FIXME: start here
+You may notice that the 'ConfigParser' object has some configurable parameters,
+such as 'usedefault'.  In case you're not familiar with the Haskell syntax
+for working with these, you can use syntax like this to set these options:
+
+>let cp2 = cp { usedefault = False }
+
+This will create a new 'ConfigParser' that is the same as @cp@ except for
+the 'usedefault' field, which is now always False.  The new object will be
+called @cp2@ in this example.
 -}
 
 {- $reading
diff --git a/libsrc/MissingH/ConfigParser/Types.hs b/libsrc/MissingH/ConfigParser/Types.hs
index 5859947..0e5fbde 100644
--- a/libsrc/MissingH/ConfigParser/Types.hs
+++ b/libsrc/MissingH/ConfigParser/Types.hs
@@ -57,7 +57,14 @@ type OptionSpec = String
 {- | Storage of options. -}
 type CPOptions = FiniteMap OptionSpec String
 
-{- | The main data storage type (storage of sections). -}
+{- | The main data storage type (storage of sections).
+
+PLEASE NOTE: This type is exported only for use by other modules under
+MissingH.ConfigParser.  You should NEVER access the FiniteMap in a ConfigParser
+directly.  This type may change in future releases of MissingH, which could
+break your programs.  Please retrict yourself to the interface in
+'MissingH.ConfigParser'.
+ -}
 type CPData = FiniteMap SectionSpec CPOptions
 
 {- | Possible ConfigParser errors. -}

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list