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


The following commit has been merged in the master branch:
commit 19b1e5c0b47506ce95c110099885f58f53fb6af1
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Nov 16 03:27:31 2004 +0100

    Experimental AL work for Printf
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-61)

diff --git a/ChangeLog b/ChangeLog
index 7cde91d..3f9ae2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,22 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-15 20:27:31 GMT	John Goerzen <jgoerzen at complete.org>	patch-61
+
+    Summary:
+      Experimental AL work for Printf
+    Revision:
+      missingh--head--0.5--patch-61
+
+
+    removed files:
+     libsrc/MissingH/Varargs.hs
+
+    modified files:
+     ChangeLog README libsrc/MissingH/Printf.hs
+     libsrc/MissingH/Printf/Types.hs
+
+
 2004-11-15 19:12:34 GMT	John Goerzen <jgoerzen at complete.org>	patch-60
 
     Summary:
diff --git a/README b/README
index 80ffa28..bacbe59 100644
--- a/README
+++ b/README
@@ -35,6 +35,8 @@ Major Features
 
  * Other utilities for threads, parers, filenames, etc.
 
+ * Printf utilities for formatting strings
+
 The following modules are are provided at this time, and more are
 likely to follow:
 
@@ -89,6 +91,10 @@ MissingH.Parsec          * Invert the sense of a parser
 
 MissingH.Path            * Split apart filename components
 
+MissingH.Printf          * Format strings using C-like syntax
+                         * Support for args as a list or as
+                           a variable-length argument
+
 MissingH.Str             * Leading/trailing whitespace removal
                          * Beginning/ending tests
                          * Joining, splitting, and truncation
diff --git a/libsrc/MissingH/Printf.hs b/libsrc/MissingH/Printf.hs
index 8b1519d..6b4b0ba 100644
--- a/libsrc/MissingH/Printf.hs
+++ b/libsrc/MissingH/Printf.hs
@@ -108,24 +108,9 @@ mkflags x =
         in
         flags''
 
-{- | List version of 'vsprintf'. -}
-
-sprintf :: String -> [Value] -> String
-sprintf [] [] = []
-sprintf ('%' : '%' : xs) y = '%' : sprintf xs y
-{-
-sprintf ('%' : xs) (y : ys) = (fromValue y) ++ sprintf xs ys
-sprintf ('!' : xs) (y : ys) = 
-    show (((fromValue y)::Int) + 1) ++ sprintf xs ys -}
-
-{-
-sprintf ('%' : t : xs) (y:ys) = 
-    let cv = get_conversion_func t y [] Nothing Nothing
-        in
-        cv ++ sprintf xs ys
--}
-
-sprintf ('%' : xs) (y : ys) =
+--type LookupFunc a :: String -> a -> (String, String, a)
+normLookup :: String -> [Value] -> (String, String, [Value])
+normLookup xs (y : ys) =
     case matchRegexAll sprintfre xs of
          Nothing -> error $ "Problem in format string at %" ++ xs
          --Just (_, _, r, x) -> "<" ++ show x ++ ">" ++ sprintf r ys
@@ -139,11 +124,31 @@ sprintf ('%' : xs) (y : ys) =
                  flags = mkflags flagstr
                  in
                  --(show width) ++ sprintf remainder ys
-                 fix_width flags width ((get_conversion_func fmt y flags width prec)) ++ sprintf remainder ys
+                 (fix_width flags width ((get_conversion_func fmt y flags width prec)), remainder, ys)
          _ -> error $ "Problem matching format string at %" ++ xs
-
+    
+{- | List version of 'vsprintf'. -}
+sprintf :: String -> [Value] -> String
+sprintf [] [] = []
+sprintf ('%' : '%' : xs) y = '%' : sprintf xs y
+sprintf ('%' : xs) y =
+    let (this, remainder, ys) = normLookup xs y
+        in
+        this ++ sprintf remainder ys
 sprintf (x:xs) y = x : sprintf xs y
 
+{-
+sprintf :: String -> [Value] -> String
+sprintf = sprintfG id sprintf
+-}
+
+{-
+{- | Association list printing -}
+sprintfAL :: String -> PrintfAL -> String
+sprintfAL [] _ = []
+sprintfAL ('%' : '%' : xs) y = '%' : sprintfAL xs y
+sprintfAL ('%' : xs) (y : ys) =
+-}
 {- | Given a format string and zero or more arguments, return a string
 that has formatted them appropriately.  This is the variable argument version
 of 'sprintf'. -}
diff --git a/libsrc/MissingH/Printf/Types.hs b/libsrc/MissingH/Printf/Types.hs
index 0c9c677..0a75389 100644
--- a/libsrc/MissingH/Printf/Types.hs
+++ b/libsrc/MissingH/Printf/Types.hs
@@ -42,6 +42,7 @@ module MissingH.Printf.Types where
 
 import System.IO
 import Data.Ratio
+import Data.FiniteMap
 
 -- data Wrapped a = Wrapped a
 
@@ -51,6 +52,9 @@ data Value =
            | ValueChar Char
              deriving (Eq, Show)
 
+type PrintfAL = [(String, Value)]
+type PrintfFM = FiniteMap String Value
+
 showValue :: Value -> String
 showValue (ValueRational x) = show x
 showValue (ValueChar x) = [x]
@@ -60,7 +64,7 @@ class PFType a where
     toValue :: a -> Value
     fromValue :: Value -> a
 
-instance Real a => PFType a where
+instance (Real a) => PFType a where
     toValue = ValueRational . toRational
     fromValue = error "fromValue to generic Real not supported"--fromRational . fromValue
 
diff --git a/libsrc/MissingH/Varargs.hs b/libsrc/MissingH/Varargs.hs
deleted file mode 100644
index 594125b..0000000
--- a/libsrc/MissingH/Varargs.hs
+++ /dev/null
@@ -1,68 +0,0 @@
-{- arch-tag: Varargs main file
-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.Varargs
-   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
-
-
-Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
-
-Inspiration and ideas from haskell-xml-rpc by Bjorn Bringert
-
--}
-
-module MissingH.Varargs where
-
-import Data.Dynamic
-import Data.Typeable
-
-isfunc :: Typeable a => a -> Bool
-isfunc x = (length $ typerepArgs $ typeOf x) > 1
-    
-
---callit :: (a -> b) -> ([b] -> c) -> c
---callit :: Typeable (a, b, c, d) => (a -> b) -> c -> d
-
-data EndOrRecurse a b = Recurse (a -> EndOrRecurse a b)
-                      | End b
-                        deriving (Eq, Typeable)
-
-printeor :: EndOrRecurse a String -> String
-printeor (End x) = "End " ++ x
-printeor (Recurse _) = "Recurse"
-
---toeor :: (Typeable a, Typeable b, Typeable c, Typeable (EndOrRecurse b c)) => a -> EndOrRecurse b c
-toeor f =
-    let d = toDyn f 
-        in
-        if isfunc f then
-           Recurse (case fromDynamic d of
-                    Nothing -> error "Couldn't get func back for recurse"
-                    Just x -> x)
-        else End (case fromDynamic d of
-                  Nothing -> error "Couldn't get item back for end"
-                  Just x -> x)
-
-test = (toeor "foo")::EndOrRecurse String String

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list