packages feed

Tables (empty) → 0.1.0.0

raw patch · 5 files changed

+273/−0 lines, 5 filesdep +basedep +cookbooksetup-changed

Dependencies added: base, cookbook

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Nate Pisarski++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Nate Pisarski nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Main.hs view
@@ -0,0 +1,147 @@+{- |+   Module      :   Tables.Tables2+   Copyright   :   (c) 2014 by Nate Pisarski+   License     :   BSD3+   Maintainer  :   nathanpisarski@gmail.com+   Stability   :   Stable+   Portability :   Portable (Standalone - ghc)+   Database client for the Quill2 database language. Use this, as Tables1 will be deprecated on June 1st, 2014.+-}+module Main(main,dispatch) where++import qualified Cookbook.Project.Quill.Quill2.Meta as Qm+import qualified Cookbook.Essential.Meta as Cm++import qualified Cookbook.Ingredients.Lists.Modify as Md+import System.IO+import System.Environment+import System.Exit++allArgs = [("Add a Quill","add x to y as z | add x to y | add x as table | add x as list"),+           ("Remove a Quill","remove x from y | remove x"),+           ("Change a Quill","change x in y to z"),+           ("Get a quill", "get x from y | get x | list"),+           ("Combine Quills", "map x to y as z | combine x with y as z")]+main = do+  arguments <- getArgs+  database  <- Qm.fromFile (head arguments)+  dispatch database (head arguments) arguments+  putStrLn "Done"++qError :: Qm.QuillStatus a -> IO a+qError x = case x of+  (Qm.QuillSuccess a)  -> return a -- FIXME make this handle the cases, not complain about them.+  (Qm.QuillMultiple a) -> do+    putStrLn ("Multiple " ++ a ++ " exist in file. Exiting. Fix manually")+    exitFailure+  (Qm.QuillMissing a)  -> do+    putStrLn (a ++ " Missing from file. Exiting. Fix manually.")+    exitFailure+  ++dispatch :: [Qm.Quill] -> String -> [String] -> IO ()+dispatch database fName ("change":x:"in":y:"to":z:w) = do+  qu <- qError (Qm.getQuill database y)+  case (snd qu) of+    (Qm.Table c) -> do+      myDB <- (qError (Qm.changeItem database (Qm.ATable (y,x,z))))+      Qm.toFile fName myDB+    (Qm.List c)  -> do+      mod <- qError $ Qm.removeItem database (y,x) -- FIXME make QuillAddition work for lists.+      myDB <- (qError (Qm.addItem mod (Qm.AList (y,z))))+      Qm.toFile fName myDB+  dispatch database fName w++dispatch database fName ("add":x:"to":y:"as":z:w) = do+  myDB <- (qError (Qm.addItem database (Qm.ATable (y,z,x))))+  Qm.toFile fName myDB+  dispatch database fName w++dispatch database fName ("add":x:"to":y:z) = do+  myDB <- (qError (Qm.addItem database (Qm.AList (y,x))))+  Qm.toFile fName myDB+  dispatch database fName z++dispatch database fName ("add":x:"as":y:w) = do+  fl <- Cm.filelines fName+  writeFile fName (unlines ((y ++ "(" ++ x ++ "){}"):fl))+  dispatch database fName w+  +dispatch database fName ("remove":x:"from":y:z) = do+  myDB <- qError (Qm.removeItem database (y,x))+  Qm.toFile fName $ myDB+  dispatch database fName z++dispatch database fName ("remove":x:y) = do+  Qm.toFile fName (Qm.removeQuill database x)+  dispatch database fName y++dispatch database fName ("get":x:"from":y:z) = do+  (qError $ Qm.lookUp database (y,x)) >>= putStrLn +  dispatch database fName z++dispatch database fName ("get":x:y) = do+  myDB <- (qError (Qm.getQuill database x))+  case (snd myDB) of+    (Qm.List a) -> mapM_ putStrLn (map ppTable [(show fi,se) | fi <- [0..length a], se <- a])+    (Qm.Table a) -> mapM_ putStrLn (map ppTable a)+  dispatch database fName y++dispatch database fName ("list":y) = do+  mapM_ listOff database++-- Composite functions+dispatch database fName ("map":x:"to":y:"as":w:z) = do+  l1 <- qError (Qm.getQuill database x)+  l2 <- qError (Qm.getQuill database y)+  let l1list = case (snd l1) of+        (Qm.List a)  -> a+        (Qm.Table _) -> error "Error! Attempting to map table"+  let l2list = case (snd l2) of+        (Qm.List a)  -> a+        (Qm.Table _) -> error "Error! Attempting to map table"+  Qm.toFile fName ((w,Qm.Table (zip l1list l2list)):database)+  dispatch database fName z++dispatch database fName ("combine":x:"with":y:"as":w:z) = do+  l1 <- qError (Qm.getQuill database x)+  l2 <- qError (Qm.getQuill database y)+  case snd l1 of+    (Qm.List a)  -> case (snd l2) of+      (Qm.List b)  -> Qm.toFile fName ((w,Qm.List (b ++ a)):database)+      (Qm.Table b) -> error "Error! Attempted to combine a table and list"+    (Qm.Table a) -> case (snd l2) of+      (Qm.Table b) -> Qm.toFile fName ((w,Qm.Table (b ++ a)):database)+      (Qm.List b)  -> error "Error! Attempted to combine a table and list"+  dispatch database fName z++dispatch database fname ("file":y:z) = do+  fl <- Cm.filelines y+  mapM_ (dispatch database fname) (map (`Md.splitOn` ' ') fl)+  dispatch database fname z++dispatch database fname ("repl":_) = do+  repl database fname+  +dispatch database fName ("help":y) = do+  mapM_ putStrLn (map ppTable allArgs)+  dispatch database fName y+  +dispatch _ _ [] = return ()+dispatch fName db ("and":xs) = dispatch fName db xs+dispatch fName db (x:xs) = do+  putStrLn ("Did not recognize command: "++x)+  dispatch fName db xs++ppTable :: (String, String) -> String+ppTable (a,b) = Cm.flt [a," : ",b]++listOff :: Qm.Quill -> IO ()+listOff x = case (snd x) of+  (Qm.Table _) -> putStrLn $ "Table " ++ (fst x)+  (Qm.List _)  -> putStrLn $ "List " ++ (fst x)++repl fname dbase = do+  inp <- Cm.prompt "$ "+  dispatch fname dbase(Md.splitOn inp ' ')+  repl fname dbase
+ README.md view
@@ -0,0 +1,27 @@+Tables+------+Tables is a command-line program for accessing Quill databases. It supports an English-like argument structure, typed Elements, truly whitespace independant parsing, and some advanced composite functions.++## Argument rundown+Tables [filename] get x from y+Tables [filename] get x+Tables [filename] add x as y+Tables [filename] add x to y as z+Tables [filename] remove x from y+Tables [filename] remove x+Tables [filename] change x in y to z+Tables [filename] map x to y as z+Tables [filename] combine x with y as z+Tables [filename] file x+Tables [filename] list+Tables [filename] x and y and...+Tables [filename] repl++## Table syntax+The actual flat file has a somewhat human readable syntax. Here is a file showing all possible use cases:++    table(tableName){`preserve whitespace`:val;key1:val1;}+	list(listName){a;b;c} /* I'm a comment! */++### Sales pitch+Tables is relatively safe (it won't delete its own file anymore, and probably won't burn your house down). It is built upon a rock-solid library (Cookbook) and a slightly-less rock-solid concept. The Haskell type system makes the base Quill library safe in regards to unexpected behavior, although there are some errors that Tables cannot recover from.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Tables.cabal view
@@ -0,0 +1,67 @@+-- Initial Tables.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name:                Tables++-- The package version.  See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+synopsis:            A client for Quill databases++-- A longer description of the package.+-- description:         ++-- The license under which the package is released.+license:             BSD3++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Nate Pisarski++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer:          nathanpisarski@gmail.com++-- A copyright notice.+-- copyright:           ++category:            Database++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+extra-source-files:  README.md++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.10+++executable Tables+  -- .hs or .lhs file containing the Main module.+   main-is: Main.hs+  +  -- Modules included in this executable, other than Main.+  -- other-modules:       +  +  -- LANGUAGE extensions used by modules in this package.+  -- other-extensions:    +  +  -- Other library packages from which modules are imported.+  build-depends:       base >=4.6 && <4.7, cookbook >=2.3 && <2.4+  +  -- Directories containing source files.+  -- hs-source-dirs:      +  +  -- Base language which the package is written in.+  default-language:    Haskell2010+