cookbook 1.5.0.0 → 2.0.0.0
raw patch · 9 files changed
+168/−12 lines, 9 files
Files
- Cookbook/Essential/IO.hs +9/−1
- Cookbook/Ingredients/Lists/Modify.hs +15/−1
- Cookbook/Ingredients/Tupples/Look.hs +1/−1
- Cookbook/Project/Context/Context.hs +33/−0
- Cookbook/Project/Quill/Quill.hs +67/−0
- Cookbook/Recipes/Algorithm.hs +27/−6
- Cookbook/Recipes/DataStructures.hs +9/−0
- Cookbook/Recipes/Math.hs +5/−1
- cookbook.cabal +2/−2
Cookbook/Essential/IO.hs view
@@ -1,10 +1,12 @@ --Cookbook.Essential.IO --IO is the only Cookbook library to import System modules. As the name states, Cookbook.IO makes IO --easier and less error-prone by wrapping common IO "gotchas" in a function.-module Cookbook.Essential.IO(filelines,prompt,inhome,getHomePath) where+module Cookbook.Essential.IO(filelines,prompt,inhome,getHomePath,filename,modulename) where import qualified System.IO as LIO import qualified System.IO.Strict as SIO+import qualified Cookbook.Essential.Continuous as Ct+import qualified Cookbook.Ingredients.Lists.Modify as Md import System.Environment import System.Directory @@ -31,3 +33,9 @@ getHomePath x = do home <- getHomeDirectory return (home ++ x)++filename :: String -> String+filename = Md.rev . ((flip Ct.before) '/') . Md.rev++modulename :: String -> String+modulename = Md.rev . ((flip Ct.after) '/') . Md.rev
Cookbook/Ingredients/Lists/Modify.hs view
@@ -1,13 +1,14 @@ --Cookbook.Ingredients.Lists.Modify --Library for altering the contents of a list. -module Cookbook.Ingredients.Lists.Modify(rev,rm,splitOn,snipe,insert,between,linesBetween) where+module Cookbook.Ingredients.Lists.Modify(rev,rm,splitOn,snipe,insert,between,linesBetween,surroundedBy) where import qualified Cookbook.Essential.Continuous as Cnt import qualified Cookbook.Essential.Common as Cm import qualified Cookbook.Ingredients.Functional.Break as Br import qualified Cookbook.Ingredients.Lists.Access as Ac+ -- | Reverses a list rev :: [a] -> [a] rev [] = []@@ -43,3 +44,16 @@ intersperse [x] _ = [x] intersperse (x:xs) c = x:c : intersperse xs c +-- | Perform a function on the last element of a list.+onLast :: (a -> a) -> [a] -> [a]+onLast _ [] = []+onLast f [x] = f x : []+onLast f (x:xs) = x : onLast f xs++(?) :: (a -> b) -> (a -> b) -> Bool -> (a -> b)+(?) f1 f2 it = (if it then f1 else f2)+++surroundedBy :: (Eq a) => [a] -> (a,a) -> [[a]] -- Map checks if a or b are not elememts.+surroundedBy x (a,b) = if or (map (not . (flip elem) x) [a,b]) then [] else recurse+ where recurse = Cnt.before (Cnt.after x a) b : surroundedBy (Cnt.after x b) (a,b)
Cookbook/Ingredients/Tupples/Look.hs view
@@ -10,7 +10,7 @@ -- | Returns all second elements where (fst t) matches the input. lookList :: (Eq a) => [(a,b)] -> a -> [b]-lookList a b = [d | (c,d) <- a, c == b]+lookList a b = map snd $ filter (\(c,d) -> c == b) a -- | Swap the order of a second-degree tupple. swp :: (a,b) -> (b,a)
+ Cookbook/Project/Context/Context.hs view
@@ -0,0 +1,33 @@+module Cookbook.Project.Context.Context(parseContexts,skim) where++import qualified Cookbook.Ingredients.Lists.Modify as Md+import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Ingredients.Functional.Break as Br+import qualified Cookbook.Ingredients.Tupples.Look as Lk+import qualified Cookbook.Ingredients.Lists.Replace as Rp++import qualified Cookbook.Essential.IO as CIO++import System.Directory++-- Binary search capabilities+skim :: FilePath -> IO [(String,FilePath)]+skim x =+ do+ allFiles <- getDirectoryContents x+ return $ zip (allFiles) (map ((x++"/")++) allFiles)++--Helper functions+isGlobalCall x = and [x `Ac.contains` "{=",x `Ac.contains` "=}"]+getGlobalName x = Md.between x ('=','=')++-- Parsing+parseContexts :: [(String,String)] -> [String] -> [String] -- Returns a list of shell commands+parseContexts _ [] = []+parseContexts cmdList (line:lines)+ | isGlobalCall line = parseGlobal cmdList line (Br.filterBreak notEnd lines) : parseContexts cmdList (Br.removeBreak notEnd lines)+ | otherwise = parseContexts cmdList lines+ where notEnd = (\c -> not (c `Ac.contains` ("{"++getGlobalName line++"}")))++parseGlobal :: [(String,String)] -> String -> [String] -> String+parseGlobal cmdList header lines = (head $ Lk.lookList cmdList (getGlobalName header)) ++ " " ++ Rp.replace (unlines lines) ('\n',' ')
+ Cookbook/Project/Quill/Quill.hs view
@@ -0,0 +1,67 @@+module Cookbook.Project.Quill.Quill(tblNames,tables,getTable,lookUp,createTable,removeTable,removeItem,addItem,tableToString,changeItem) where+import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Essential.Continuous as Ct+import qualified Cookbook.Ingredients.Lists.Remove as Rm+import qualified Cookbook.Ingredients.Lists.Modify as Md+import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Ingredients.Tupples.Look as Lk+import qualified Cookbook.Recipes.Sanitize as Sn+--Custom data+data Table = Table {name :: String, info :: [(String,String)]}++-- Parsing+prepare :: [String] -> String+prepare = ((flip Sn.blacklist) [' ','\n']) . Cm.flt++tokenize :: [a] -> [(a,a)]+tokenize [] = []+tokenize [x] = []+tokenize (x:y:xs) = (x,y) : tokenize xs++-- Table access+tblNames :: String -> [String]+tblNames x = (Ct.before x '{') : Md.surroundedBy x ('}','{')+++headlessData :: String -> [[String]]+headlessData x = map ((flip Md.splitOn) ';') $ (Md.surroundedBy x ('{','}'))++tokenLists :: [[String]] -> [[(String,String)]]+tokenLists x = map tokenize $ map Cm.flt ( map (map ((flip Md.splitOn) ':')) x)+++-- API functions+tables :: [String] -> [(String,[(String,String)])]+tables x = let y = prepare x in+ zip (tblNames y) $ tokenLists (headlessData y)++getTable :: [(String,[(String,String)])] -> String -> [(String,String)]+getTable x c = Cm.flt $ Lk.lookList x c++lookUp :: [(String,[(String,String)])] -> (String,String) -> [String]+lookUp x (c,d) = ((flip Lk.lookList) d) $ getTable x c++createTable :: [(String,[(String,String)])] -> String -> [(String,[(String,String)])]+createTable x c = (c,[]) : x++removeTable :: [(String,[(String,String)])] -> String -> [(String,[(String,String)])]+removeTable x c = [e | e@(d,_) <- x, d /= c]++removeItem :: [(String,[(String,String)])] -> (String,String) -> [(String,[(String,String)])]+removeItem [] _ = []+removeItem ((tbl,ite):re) (tb,it)+ | tbl == tb = (tbl,filter (\(c,d) -> c /= it) ite) : removeItem re (tb,it)+ | otherwise = (tbl,ite) : removeItem re (tb,it)+ +addItem :: [(String,[(String,String)])] -> String -> (String,String) -> [(String,[(String,String)])]+addItem [] _ _ = []+addItem ((a,b):c) tb it = if a == tb then (a,it:b) : addItem c tb it else (a,b) : addItem c tb it++changeItem :: [(String,[(String,String)])] -> (String,String) -> String -> [(String,[(String,String)])]+changeItem db (tb,it) c = addItem (removeItem db (tb,it)) tb (it,c)++tableToString :: (String,[(String,String)]) -> String+tableToString (x,b) = x ++ "{" ++ (Cm.flt (map detokenize b)) ++ "}"+ where detokenize (a,b) = a ++ ":" ++ b ++ ";"++
Cookbook/Recipes/Algorithm.hs view
@@ -1,11 +1,32 @@ --Cookbook.Recipes.Algorithm --Used for traversing data structures.-module Cookbook.Recipes.Algorithm(climb) where+module Cookbook.Recipes.Algorithm(climb,genMatrix) where import Cookbook.Recipes.DataStructures+import Cookbook.Ingredients.Lists.Modify -climb :: (Tree a) -> a -> [a]-climb x c = case x of (Empty) -> [];- (Branch a (Empty) b) -> a : climb b c- (Branch a b (Empty)) -> a : climb b c- (Branch a b d) -> a : climb b c ++ climb d c+-- | Gets all the nodes in a binary tree, putting them in a list.+climb :: (Tree a) -> [a]+climb x = case x of (Empty) -> [];(Branch a (Empty) b) -> a : climb b;+ (Branch a b (Empty)) -> a : climb b;+ (Branch a b d) -> a : climb b ++ climb d ++-- | Provides map-like behavior for binary trees.+treeMap :: (Tree a) -> (a -> a) -> (Tree a)+treeMap tr f = case tr of Empty -> Empty;+ (Branch a (Empty) z@(Branch c _ _)) -> (Branch (f c) (treeMap z f) (Empty));+ (Branch a z@(Branch b _ _) (Empty)) -> (Branch (f b) (Empty) (treeMap z f))++-- | Provides filter-like behavior for binary trees.+treeFilter :: (Tree a) -> (a -> Bool) -> (Tree a)+treeFilter Empty f = Empty+treeFilter (Branch a (Empty) z@(Branch b _ _)) f = if (f a) then (Branch a (Empty) (treeFilter z f)) else Empty+treeFilter (Branch a z@(Branch b _ _) (Empty)) f = if (f a) then (Branch a (treeFilter z f) (Empty)) else Empty++-- | Generates a matrix (coord1,coord2,a) with the specified data to null it out.+genMatrix :: (Int,Int) -> a -> [((Int,Int),a)]+genMatrix (a,b) c = helper (0,0)+ where helper (d,e)+ | d == a = []+ | e == b = ((d,e),c) : helper (d+1,0)+ | otherwise = ((d,e),c) : helper (d,e+1)
Cookbook/Recipes/DataStructures.hs view
@@ -2,7 +2,16 @@ --Higher-level data structures for use in the rest of Cookbook. module Cookbook.Recipes.DataStructures(Tree(..),) where +-- | Cookie-cutter implementation of a binary tree. data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show)--add a "map" and "filter" function for Tree.++++++++
Cookbook/Recipes/Math.hs view
@@ -1,6 +1,6 @@ --Cookbook.Recipes.Math --A library for mathematical formulas, parsing, and conversions.-module Cookbook.Recipes.Math(inc,dec,sqr,avg,stdev) where+module Cookbook.Recipes.Math(inc,dec,sqr,avg,stdev,fact) where --Simple, helper arithmetic functions. inc :: (Num a) => a -> a@@ -19,3 +19,7 @@ stdev :: (Fractional a, Floating a) => [a] -> a stdev x = sqrt $ diffs / realToFrac (length x) where diffs = sum $ [sqr $ a - avg x| a <- x]++-- Simple factorial, using fold.+fact :: Int -> Int+fact x = foldl (*) x [1..dec x]
cookbook.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.5.0.0+version: 2.0.0.0 -- A short (one-line) description of the package. synopsis: A delicious set of interdependant libraries.@@ -48,7 +48,7 @@ library -- Modules exported by the library.- exposed-modules: Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Recipes.DiffStat, Cookbook.Project.Configuration.Configuration, Cookbook.Project.Scribe.Scribe, Cookbook.Project.Preprocess.Preprocess, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Remove, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Detect, Cookbook.Project.Groups.Groups, Cookbook.Recipes.Sanitize, Cookbook.Ingredients.Lists.Replace, Cookbook.Recipes.Math,Cookbook.Recipes.DataStructures,Cookbook.Recipes.Algorithm+ exposed-modules: Cookbook.Project.Context.Context, Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Recipes.DiffStat, Cookbook.Project.Configuration.Configuration, Cookbook.Project.Scribe.Scribe, Cookbook.Project.Preprocess.Preprocess, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Remove, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Detect, Cookbook.Project.Groups.Groups, Cookbook.Recipes.Sanitize, Cookbook.Ingredients.Lists.Replace, Cookbook.Recipes.Math,Cookbook.Recipes.DataStructures,Cookbook.Recipes.Algorithm, Cookbook.Project.Quill.Quill -- Modules included in this library but not exported. -- other-modules: