packages feed

hampp 0.2 → 0.2.1

raw patch · 2 files changed

+24/−6 lines, 2 filesdep +Glob

Dependencies added: Glob

Files

Main.lhs view
@@ -1,5 +1,5 @@ % Hampp
-% version 0.2
+% version 0.2.1
 % Public domain
 
 \input birdstyle
@@ -32,6 +32,7 @@ > import System.Directory;
 > import System.Environment;
 > import System.FilePath;
+> import System.FilePath.Glob;
 > import System.IO;
 > import System.IO.Error;
 
@@ -87,6 +88,8 @@ >  liftA2 (++) (includeOne p $ rtrim v) (includeFiles p t);
 > includeFiles p (Single (Token { val = '#':'J':' ':v }) : t) =
 >  liftA2 (++) (includeMany $ rtrim v) (includeFiles p t);
+> includeFiles p (Single (Token { val = '#':'W':' ':v }) : t) =
+>  liftA2 (++) (importMany $ rtrim v) (includeFiles p t);
 > includeFiles p (x @ Block { body = v } : t) = liftA2
 >  (\y -> (x { body = y } :)) (includeFiles p v) (includeFiles p t);
 > includeFiles p (h : t) = (h :) <$> includeFiles p t;
@@ -99,12 +102,21 @@ >  >>= either (fail . show) (includeFiles p);
 
 To look for wildcard files, it will use only the current directory, or a
-different directory if that is specified in the filename to include. Note
-that on Windows, it must match case insensitive, and on UNIX, it has to be
-case sensitive.
+different directory if that is specified in the filename to include.
 
 > includeMany :: FilePath -> IO [Ast];
-> includeMany f = error "Wildcard includes not currently implemented";
+> includeMany = glob >=> fmap join . sequence . map (includeOne ["."])
+>  . sort;
+
+There is also wildcard imports. These ignore the contents of the files and
+instead just use their existence.
+
+> importMany :: String -> IO [Ast];
+> importMany s = either (fail . show) id . parseBy mySpec "<macro>" . f
+>  <$> glob (((\x -> bool x '/' (x == '.')) <$> s) ++ "/[A-Z]*.*hs")
+> where {
+>   f = (>>= (("import " ++ s ++ ".") ++) . (++ ";\n") . takeBaseName);
+> };
 
 Some files are literate Haskell, or other formats, so it must know how to
 load them differently.
hampp.cabal view
@@ -2,7 +2,7 @@ -- The package version. See the Haskell package versioning policy
 -- http://www.haskell.org/haskellwiki/Package_versioning_policy for
 -- standards guiding when and how versions should be incremented.
-Version:             0.2
+Version:             0.2.1
 Synopsis:            Haskell macro preprocessor
 License:             PublicDomain
 Category:            Preprocessor
@@ -22,6 +22,7 @@     containers >= 0.4.0.0 && < 0.5,
     directory >= 1.1 && < 1.2,
     filepath >= 1.2.0.0 && < 1.4,
+    Glob >= 0.7 && < 0.8,
     preprocessor-tools >= 0.1.2 && < 0.2
 
 ---- Features:
@@ -31,9 +32,14 @@ -- Binary and ASCII integer literals
 -- Include files (Haskell and literate Haskell)
 -- Remove commas at end of {a,b,c,} and [a,b,c,]
+-- Wildcard includes/imports
 
 ---- To-do:
 -- Other file formats (C header, CSV, XML, etc)
 -- Layout mode
 -- Pool strings
 -- Any other feature that you might want; please ask
+
+---- Changes in version 0.2.1:
+-- Wildcard includes added
+-- Wildcard imports added