[make cabal file parser more robust, use -o to specify hl file output name clean up library creating code a bit
John Meacham <john@repetae.net>**20060307020644] hunk ./Ho/Build.hs 140
-    where loop []     = fail ("checkForHoModule: Module "++m++" not found.")
+    where loop []     = return $ fail ("checkForHoModule: Module "++m++" not found.")
hunk ./Ho/Library.hs 1
-module Ho.Library
-    (loadLibraries, createLibrary, parseLibraryDescription
+module Ho.Library(
+    loadLibraries,
+    createLibrary
hunk ./Ho/Library.hs 6
-import HsSyn
+import Control.Monad(when,foldM)
+import Data.List(sort)
+import Data.Monoid
+import qualified Data.Map as Map
+import System.IO
+import Char
+
+import GenUtil
hunk ./Ho/Library.hs 17
-import GenUtil
-import Options(options, optHls)
+import HsSyn
+import Options
hunk ./Ho/Library.hs 20
+import qualified CharIO
+import qualified FlagDump as FD
+import Util.Gen
hunk ./Ho/Library.hs 25
-import Control.Monad(when,foldM)
-import Data.List(sort)
-import qualified Data.Map as Map
-import Data.Monoid
-import System.IO
hunk ./Ho/Library.hs 63
+
+
hunk ./Ho/Library.hs 66
-              -> [(String,String)]
hunk ./Ho/Library.hs 67
-createLibrary fp desc = do
-  let field x = lookup x desc
-  let jfield x = maybe (error "createLibrary: description lacks required field "++show x) id $ field x
-  let mfield x = maybe [] (words . map (\c -> if c == ',' then ' ' else c)) $ field x
-  let name  = jfield "name"
-      hmods = mfield "hidden-modules"
-      emods = mfield "exposed-modules"
-  let noc _ hsm = fail ("createLibrary: won't compile anything, requested: "++show (map hsModuleName hsm))
-  let allmods  = sort $ map Module (emods ++ hmods)
-  let fun ho m = do mho <- checkForHoModule m
-                    case mho of
-                      Nothing      -> fail (show fp++" depends not done.")
-                      Just (_,ho') -> return $ mappend ho ho'
-  ho <- foldM fun mempty allmods
-  let homods = sort $ Map.keys (hoExports ho)
-  when (homods /= allmods) $
-      putErrDie ("Final ho consists of wrong modules:\nexpected: \t"
-                 ++show allmods++"\nencountered: \t"++show homods)
-  let ho' = ho { hoExports = Map.difference (hoExports ho)
-                             (Map.fromList [(Module x,()) | x <- hmods]) }
-  let pdesc = [(packString n, packString v) | (n,v) <- desc ]
-  writeLibraryFile fp $ Library pdesc ho "" 0
+createLibrary fp = do
+    putVerboseLn $ "Creating library from description file: " ++ show fp
+    desc <- readDescFile fp
+    when verbose2 $ mapM_ print desc
+    let field x = lookup x desc
+    let jfield x = maybe (error "createLibrary: description lacks required field "++show x) id $ field x
+    let mfield x = maybe [] (words . map (\c -> if c == ',' then ' ' else c)) $ field x
+    let name  = jfield "name"
+        vers  = jfield "version"
+        hmods = mfield "hidden-modules"
+        emods = mfield "exposed-modules"
+    let noc _ hsm = fail ("createLibrary: won't compile anything, requested: "++show (map hsModuleName hsm))
+    let allmods  = sort $ map Module (emods ++ hmods)
+    let fun ho m = do mho <- checkForHoModule m
+                      case mho of
+                        Nothing      -> fail (show fp ++ ": could not find module " ++ show m)
+                        Just (_,ho') -> return $ mappend ho ho'
+    ho <- foldM fun mempty allmods
+    let homods = sort $ Map.keys (hoExports ho)
+    when (homods /= allmods) $
+        putErrDie ("Final ho consists of wrong modules:\nexpected: \t"
+                   ++show allmods++"\nencountered: \t"++show homods)
+    let ho' = ho { hoExports = Map.difference (hoExports ho)
+                               (Map.fromList [(Module x,()) | x <- hmods]) }
+    let pdesc = [(packString n, packString v) | (n,v) <- desc ]
+    let outName = case optOutName options of
+            "hs.out" -> name ++ "-" ++ vers ++ ".hl"
+            fn -> fn
+    writeLibraryFile outName $ Library pdesc ho "" 0
+
+parseLibraryDescription :: Monad m => String -> m [(String,String)]
+parseLibraryDescription fs =  g [] (lines (f [] fs)) where
+    --f rs ('\n':s:xs) | isSpace s = f rs (dropWhile isSpace xs)
+    f rs ('-':'-':xs) = f rs (dropWhile (/= '\n') xs)
+    f rs ('{':'-':xs) = eatCom rs xs
+    f rs (x:xs) = f (x:rs) xs
+    f rs [] = reverse rs
+    eatCom rs ('\n':xs) = eatCom ('\n':rs) xs
+    eatCom rs ('-':'}':xs) = f rs xs
+    eatCom rs (_:xs) = eatCom rs xs
+    eatCom rs [] = f rs []
+    g rs (s:ss) | all isSpace s = g rs ss
+    g rs (s:s':ss) | all isSpace s' = g rs (s:ss)
+    g rs (s:(h:cl):ss) | isSpace h = g rs ((s ++ h:cl):ss)
+    g rs (r:ss) | (':':bd') <- bd = g ((map toLower $ condenseWhitespace nm,condenseWhitespace bd'):rs) ss
+         | otherwise = fail $ "could not find ':' marker: " ++ show (rs,(r:ss)) where
+            (nm,bd) = break (== ':') r
+    g rs [] = return rs
+
+condenseWhitespace xs =  reverse $ dropWhile isSpace (reverse (dropWhile isSpace (cw xs))) where
+    cw (x:y:zs) | isSpace x && isSpace y = cw (' ':zs)
+    cw (x:xs) = x:cw xs
+    cw [] = []
+
hunk ./Ho/Library.hs 123
-parseLibraryDescription :: String -> [(String,String)]
-parseLibraryDescription = map g . f . e . lines
-    where e = filter (any (not . space))
-          f (x:(c:r):t) | space c = f ((x++" "++dropWhile space r):t)
-          f (x:t)                 = x : f t
-          f []                    = []
-          g l = let (h,(_:t)) = break (':'==) l in (h,dropWhile space t)
-          space c = c == ' ' || c == '\t'
+readDescFile :: FilePath -> IO [(String,String)]
+readDescFile fp = do
+    wdump FD.Progress $ putStrLn $ "Reading: " ++ show fp
+    fc <- CharIO.readFile fp
+    case parseLibraryDescription fc of
+        Left err -> fail $ "Error reading library description file: " ++ show fp ++ " " ++ err
+        Right ps -> return ps
hunk ./Main.hs 94
-      BuildHl hl    -> buildHl hl (optArgs o)
+      BuildHl hl    -> createLibrary hl
hunk ./Main.hs 104
-buildHl fname [pd] = do pd <- CharIO.readFile pd
-                        createLibrary fname $ parseLibraryDescription pd
-buildHl fname _    = do putErrDie "Syntax: --build-hl hl-file package-description-file"
hunk ./Options.hs 132
-    , Option []    ["build-hl"]  (ReqArg (optMode_s . BuildHl) "file.hl") "Build hakell library from given list of modules"
+    , Option []    ["build-hl"]  (ReqArg (optMode_s . BuildHl) "file.cabal") "Build hakell library from given library description file"