haskell-awk 1.2 → 1.2.0.1
raw patch · 31 files changed
+331/−89 lines, 31 filesdep ~HUnitdep ~aesondep ~attoparsecnew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: HUnit, aeson, attoparsec, base, bytestring, containers, directory, doctest, easy-file, exceptions, extra, filelock, filepath, ghc, haskell-src-exts, hint, hspec, list-t, mtl, process, template-haskell, temporary, test-framework, time, transformers
API changes (from Hackage documentation)
- System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.ListAsRow GHC.Num.Integer.Integer
- System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.ListAsRows GHC.Num.Integer.Integer
- System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.Row GHC.Num.Integer.Integer
- System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.Rows GHC.Num.Integer.Integer
+ System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.ListAsRow GHC.Integer.Type.Integer
+ System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.ListAsRows GHC.Integer.Type.Integer
+ System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.Row GHC.Integer.Type.Integer
+ System.Console.Hawk.Representable: instance System.Console.Hawk.Representable.Rows GHC.Integer.Type.Integer
Files
- CHANGELOG.md +4/−0
- README.md +3/−3
- haskell-awk.cabal +69/−55
- src/Control/Monad/Trans/OptionParser.hs +14/−6
- src/Control/Monad/Trans/State/Persistent.hs +22/−15
- src/Control/Monad/Trans/Uncertain.hs +12/−4
- src/Data/HaskellModule/Parse.hs +8/−1
- src/Data/HaskellSource.hs +8/−0
- src/System/Console/Hawk.hs +7/−0
- src/System/Console/Hawk/Args/Parse.hs +8/−1
- src/System/Console/Hawk/Context/Dir.hs +9/−2
- src/System/Console/Hawk/Interpreter.hs +9/−1
- src/System/Console/Hawk/UserExpr/CanonicalExpr.hs +1/−1
- tests/inputs/0-100 +101/−0
- tests/inputs/1-10 +10/−0
- tests/inputs/1-12 +4/−0
- tests/inputs/1-3 +3/−0
- tests/inputs/1-6 +2/−0
- tests/inputs/1-9 +3/−0
- tests/inputs/1-9commas +3/−0
- tests/inputs/1-9tabs +3/−0
- tests/inputs/equation +1/−0
- tests/inputs/example.in +5/−0
- tests/inputs/json +1/−0
- tests/inputs/passwd +1/−0
- tests/preludes/default/prelude.hs +4/−0
- tests/preludes/moduleName/prelude.hs +2/−0
- tests/preludes/moduleNamedMain/prelude.hs +2/−0
- tests/preludes/noImplicitPrelude/prelude.hs +2/−0
- tests/preludes/readme/prelude.hs +5/−0
- tests/preludes/set/prelude.hs +5/−0
CHANGELOG.md view
@@ -1,5 +1,9 @@ # What's new? +## New in 1.2.0.1+* support ghc-8.6 again and back to ghc-8.0 (Stackage LTS 9)+* fix missing test files in released tarball (#257)+ ## New in 1.2 * Added support for ghc-9.0.1, ghc-8.10 and ghc-8.8, dropped support for ghc-8.6 and below.
README.md view
@@ -34,7 +34,7 @@ different. Awk uses a specialized language designed to concisely express many text transformations, while Hawk uses the general-purpose language Haskell, which is also known for being concise, among other things. There are many standard command-line tools that can be easily approximated using-[short Haskell expressions](http://www.haskell.org/haskellwiki/Simple_Unix_tools).+[short Haskell expressions](https://wiki.haskell.org/Simple_Unix_tools). Another important difference is that while awk one-liners are self-contained, Hawk encourages the use of libraries and user-defined functions. By adding function definitions, module imports and language pragmas to Hawk's user-configurable [prelude file](https://github.com/gelisam/hawk/tree/master/doc#user-prelude), those functions, libraries and language extensions become available to Hawk one-liners. For instance, we could add a `takeLast` function extracting the last `n` elements from a list, and use it to (inefficiently) approximate `tail`:@@ -49,11 +49,11 @@ For more details, see the [presentation](http://melrief.github.io/HawkPresentation/#/) and the-[documentation](doc/README.md).+[documentation](https://github.com/gelisam/hawk/tree/master/doc/README.md). ## Installation -To install hawk, clone this repository, run `stack install`, and add `~/.local/bin` to your PATH. Alternatively, you can also use cabal, but only v1-style is currently supported: run `cabal v1-sandbox init && cabal v1-install`, and add `/.../.cabal-sandbox/bin` to your PATH.+To install hawk, either run `stack install haskell-awk` or `cabal install haskell-awk`. You should be ready to use Hawk:
haskell-awk.cabal view
@@ -4,23 +4,41 @@ -- -- see: https://github.com/sol/hpack ----- hash: 6eb7495d07ed97512f1c4161b59f59a2da447bba79e684418e34af5a402a7a55+-- hash: 7517e27fc1a323df0f63f63937abf935ca1ecdd5376effed8078a1c1dd86928a name: haskell-awk-version: 1.2+version: 1.2.0.1 synopsis: Transform text from the command-line using Haskell expressions. description: Hawk is a command line utility to process streams of text using Haskell code. It is intended to be used in a UNIX pipeline. It offers a configuration system to personalize imported modules and a way to represent values on the console. category: Console homepage: https://github.com/gelisam/hawk#readme bug-reports: https://github.com/gelisam/hawk/issues author: Mario Pastorelli <pastorelli.mario@gmail.com>, Samuel Gélineau <gelisam@gmail.com>-maintainer: Mario Pastorelli <pastorelli.mario@gmail.com>, Samuel Gélineau <gelisam@gmail.com>+maintainer: Samuel Gélineau <gelisam@gmail.com>, Jens Petersen <juhpetersen@gmail.com> license: Apache-2.0 license-file: LICENSE build-type: Custom extra-source-files: README.md CHANGELOG.md+ tests/inputs/0-100+ tests/inputs/1-10+ tests/inputs/1-12+ tests/inputs/1-3+ tests/inputs/1-6+ tests/inputs/1-9+ tests/inputs/1-9commas+ tests/inputs/1-9tabs+ tests/inputs/equation+ tests/inputs/example.in+ tests/inputs/json+ tests/inputs/passwd+ tests/preludes/default/prelude.hs+ tests/preludes/moduleName/prelude.hs+ tests/preludes/moduleNamedMain/prelude.hs+ tests/preludes/noImplicitPrelude/prelude.hs+ tests/preludes/readme/prelude.hs+ tests/preludes/set/prelude.hs source-repository head type: git@@ -28,9 +46,9 @@ custom-setup setup-depends:- Cabal >=3.0.1.0- , base >=4.13.0.0 && <5- , cabal-doctest >=1.0.8+ Cabal >=1.24.2.0+ , base >=4.9 && <5+ , cabal-doctest >=1.0.4 library exposed-modules:@@ -46,11 +64,11 @@ runtime ghc-options: -Wall build-depends:- base >=4.13.0.0 && <5- , bytestring >=0.10.10.1- , containers >=0.6.2.1- , ghc >=8.8.4- , list-t >=1.0.4+ base >=4.9 && <5+ , bytestring >=0.10.8.1+ , containers >=0.5.7.1+ , ghc >=8.0.2+ , list-t >=1 , stringsearch >=0.3.6.6 if os(windows) build-depends:@@ -99,25 +117,22 @@ src ghc-options: -Wall build-depends:- base >=4.13.0.0 && <5- , bytestring >=0.10.10.1- , containers >=0.6.2.1- , directory >=1.3.6.0- , exceptions >=0.10.4- , extra >=1.7.9- , filelock >=0.1.1.5- , filepath >=1.4.2.1- , ghc >=8.8.4+ base >=4.9 && <5+ , bytestring >=0.10.8.1+ , containers >=0.5.7.1+ , directory >=1.3.0.0+ , extra >=1.5.3+ , filelock >=0.1.0.1+ , filepath >=1.4.1.1+ , ghc >=8.0.2 , haskell-awk- , haskell-src-exts >=1.23.1- , hint >=0.9.0.3- , list-t >=1.0.4- , mtl >=2.2.2- , process >=1.6.9.0- , stringsearch >=0.3.6.6- , template-haskell >=2.15.0.0- , time >=1.9.3- , transformers >=0.5.6.2+ , haskell-src-exts >=1.18.2+ , hint >=0.7.0+ , list-t >=1+ , mtl >=2.2.1+ , process >=1.4.3.0+ , template-haskell >=2.11.1.0+ , transformers >=0.5.2.0 if os(windows) build-depends: base <0@@ -174,34 +189,33 @@ tests ghc-options: -Wall build-depends:- HUnit >=1.6.1.0- , aeson >=1.4.7.1- , attoparsec >=0.13.2.4- , base >=4.13.0.0 && <5- , bytestring >=0.10.10.1- , containers >=0.6.2.1- , directory >=1.3.6.0- , doctest >=0.16.3- , easy-file >=0.2.2- , exceptions >=0.10.4- , extra >=1.7.9- , filelock >=0.1.1.5- , filepath >=1.4.2.1- , ghc >=8.8.4+ HUnit >=1.5.0.0+ , aeson >=1.1.2.0+ , attoparsec >=0.13.1.0+ , base >=4.9 && <5+ , bytestring >=0.10.8.1+ , containers >=0.5.7.1+ , directory >=1.3.0.0+ , doctest >=0.11.4+ , easy-file >=0.2.1+ , exceptions >=0.8.3+ , extra >=1.5.3+ , filelock >=0.1.0.1+ , filepath >=1.4.1.1+ , ghc >=8.0.2 , haskell-awk- , haskell-src-exts >=1.23.1- , hint >=0.9.0.3- , hspec >=2.7.6- , list-t >=1.0.4- , mtl >=2.2.2- , process >=1.6.9.0- , stringsearch >=0.3.6.6- , template-haskell >=2.15.0.0- , temporary >=1.3- , test-framework >=0.8.2.0+ , haskell-src-exts >=1.18.2+ , hint >=0.7.0+ , hspec >=2.4.4+ , list-t >=1+ , mtl >=2.2.1+ , process >=1.4.3.0+ , template-haskell >=2.11.1.0+ , temporary >=1.2.1+ , test-framework >=0.8.1.1 , test-framework-hunit >=0.3.0.2- , time >=1.9.3- , transformers >=0.5.6.2+ , time >=1.6.0.1+ , transformers >=0.5.2.0 if os(windows) build-depends: base <0
src/Control/Monad/Trans/OptionParser.hs view
@@ -1,11 +1,17 @@-{-# LANGUAGE DeriveFunctor, LambdaCase, PackageImports, RankNTypes #-}+{-# LANGUAGE CPP, DeriveFunctor, LambdaCase, PackageImports, RankNTypes #-} -- | A typeclass- and monad-based interface for GetOpt, -- designed to look as if the options had more precise types than String. module Control.Monad.Trans.OptionParser where -import Control.Monad-import qualified Control.Monad.Fail as Fail-import "mtl" Control.Monad.Identity+import Prelude hiding (fail)++import Control.Monad hiding (fail)+#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (MonadFail, fail)+#else+import Prelude (fail)+#endif+import "mtl" Control.Monad.Identity hiding (fail) import "mtl" Control.Monad.Trans import Control.Monad.Trans.State import Data.List@@ -74,8 +80,10 @@ OptionParserT mx >>= f = OptionParserT (mx >>= f') where f' = unOptionParserT . f+#if MIN_VERSION_base(4,12,0) -instance Monad m => Fail.MonadFail (OptionParserT o m) where+instance Monad m => MonadFail (OptionParserT o m) where+#endif fail s = OptionParserT (fail s) instance MonadTrans (OptionParserT o) where@@ -366,7 +374,7 @@ -- | The value assigned to the option if the check function doesn't fail with -- an error. The check functions must return a file path. ----- >>> import Control.Monad+-- >>> import Control.Monad hiding (fail) -- >>> import System.EasyFile (doesDirectoryExist) -- >>> let testIO args tp p = runUncertainIO $ runOptionParserWith head id (const [""]) tp ["input-dir"] p args -- >>> let inputDir = const filePath
src/Control/Monad/Trans/State/Persistent.hs view
@@ -1,9 +1,12 @@-{-# LANGUAGE PackageImports, ScopedTypeVariables #-}+{-# LANGUAGE CPP, PackageImports, ScopedTypeVariables #-} -- | In which the state of a State monad is persisted to disk. module Control.Monad.Trans.State.Persistent where import Control.Applicative import Control.Monad+#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (MonadFail)+#endif import Control.Monad.IO.Class import "mtl" Control.Monad.Trans import Control.Monad.Trans.Maybe@@ -19,18 +22,18 @@ -- | Read and write the cache to a file. Not atomic.--- +-- -- >>> :{ -- do { exists <- doesFileExist f -- ; when exists $ removeFile f -- } -- :}--- +-- -- >>> withPersistentState f 0 $ modify (+1) >> get -- 1 -- >>> withPersistentState f 0 $ modify (+1) >> get -- 2--- +-- -- >>> removeFile f withPersistentState :: forall s a. (Read s, Show s, Eq s) => FilePath -> s -> State s a -> IO a@@ -41,33 +44,37 @@ sTx = mapStateT (return . runIdentity) sx -- | A monad-transformer version of `withPersistentState`.--- +-- -- >>> :{ -- do { exists <- doesFileExist f -- ; when exists $ removeFile f -- } -- :}--- +-- -- >>> withPersistentStateT f 0 $ lift (putStrLn "hello") >> modify (+1) >> get -- hello -- 1 -- >>> withPersistentStateT f 0 $ lift (putStrLn "hello") >> modify (+1) >> get -- hello -- 2--- --- +--+-- -- If the contents of the file has been corrupted, revert to the default value.--- +-- -- >>> withPersistentStateT f "." $ lift (putStrLn "hello") >> modify (++".") >> get -- hello -- ".." -- >>> withPersistentStateT f "." $ lift (putStrLn "hello") >> modify (++".") >> get -- hello -- "..."--- --- +--+-- -- >>> removeFile f-withPersistentStateT :: forall m s a. (Functor m, MonadIO m, MonadFail m, Read s, Show s, Eq s)+withPersistentStateT :: forall m s a. (Functor m, MonadIO m,+#if MIN_VERSION_base(4,12,0)+ MonadFail m,+#endif+ Read s, Show s, Eq s) => FilePath -> s -> StateT s m a -> m a withPersistentStateT f default_s sx = do Just s <- runMaybeT (get_s <|> get_default_s)@@ -80,7 +87,7 @@ get_s = do exists <- liftIO $ doesFileExist f guard exists- + -- close the file even if the parsing fails Just s <- liftIO $ withFile f ReadMode $ \h -> do file_contents <- hGetContents h@@ -88,14 +95,14 @@ [(s, "")] -> return (Just s) _ -> return Nothing return s- + get_default_s :: MaybeT m s get_default_s = return default_s -- | Combine consecutive StateT transformers into a single StateT, so the state -- can be persisted to a single file.--- +-- -- >>> let sx = modify (+10) :: StateT Int (State Int) () -- >>> let tx = lift $ modify (*2) :: StateT Int (State Int) () -- >>> execState (withCombinedState $ sx >> tx) (1, 2)
src/Control/Monad/Trans/Uncertain.hs view
@@ -1,10 +1,16 @@-{-# LANGUAGE PackageImports, RankNTypes #-}+{-# LANGUAGE CPP, PackageImports, RankNTypes #-} -- | A computation which may raise warnings or fail in error. module Control.Monad.Trans.Uncertain where -import qualified Control.Monad.Fail as Fail+import Prelude hiding (fail)++#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (MonadFail, fail)+#else+import Prelude (fail)+#endif import "mtl" Control.Monad.Trans-import "mtl" Control.Monad.Identity+import "mtl" Control.Monad.Identity hiding (fail) import "transformers" Control.Monad.Trans.Except import "transformers" Control.Monad.Trans.Writer import System.Exit@@ -32,8 +38,10 @@ UncertainT mx >>= f = UncertainT (mx >>= f') where f' = unUncertainT . f+#if MIN_VERSION_base(4,12,0) -instance Monad m => Fail.MonadFail (UncertainT m) where+instance Monad m => MonadFail (UncertainT m) where+#endif fail s = UncertainT (throwE s) instance MonadTrans UncertainT where
src/Data/HaskellModule/Parse.hs view
@@ -1,7 +1,14 @@-{-# LANGUAGE OverloadedStrings, PackageImports, RecordWildCards, ScopedTypeVariables #-}+{-# LANGUAGE CPP, OverloadedStrings, PackageImports, RecordWildCards, ScopedTypeVariables #-} -- | In which a Haskell module is deconstructed into extensions and imports. module Data.HaskellModule.Parse (readModule) where +import Prelude hiding (fail)++#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (fail)+#else+import Prelude (fail)+#endif import "mtl" Control.Monad.Trans import qualified Data.ByteString.Char8 as B import Data.List
src/Data/HaskellSource.hs view
@@ -1,9 +1,17 @@+{-# LANGUAGE CPP #-} -- | A representation of Haskell source code. -- -- Unlike haskell-src-exts, our goal is not to reconstruct detailed semantics, -- but to preserve original line numbers (if applicable). module Data.HaskellSource where +import Prelude hiding (fail)++#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (fail)+#else+import Prelude (fail)+#endif import Control.Monad.Trans.Class import Data.ByteString.Char8 as B import System.Directory
src/System/Console/Hawk.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} -- Copyright 2013 Mario Pastorelli (pastorelli.mario@gmail.com) Samuel Gélineau (gelisam@gmail.com) -- -- Licensed under the Apache License, Version 2.0 (the "License");@@ -18,7 +19,13 @@ ( processArgs ) where +import Prelude hiding (fail) +#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (fail)+#else+import Prelude (fail)+#endif import Control.Monad.Trans import Data.List import Language.Haskell.Interpreter
src/System/Console/Hawk/Args/Parse.hs view
@@ -1,7 +1,14 @@-{-# LANGUAGE OverloadedStrings, PackageImports, ScopedTypeVariables #-}+{-# LANGUAGE CPP, OverloadedStrings, PackageImports, ScopedTypeVariables #-} -- | In which Hawk's command-line arguments are structured into a `HawkSpec`. module System.Console.Hawk.Args.Parse (parseArgs) where +import Prelude hiding (fail)++#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (fail)+#else+import Prelude (fail)+#endif import Data.Char (isSpace) import Data.Maybe import "mtl" Control.Monad.Trans
src/System/Console/Hawk/Context/Dir.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE PackageImports #-}+{-# LANGUAGE CPP, PackageImports #-} -- | About the directory in which the context is persited. module System.Console.Hawk.Context.Dir ( createDefaultContextDir@@ -6,7 +6,14 @@ , checkContextDir ) where -import Control.Monad+import Prelude hiding (fail)++import Control.Monad hiding (fail)+#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (fail)+#else+import Prelude (fail)+#endif import "mtl" Control.Monad.Trans import System.Directory import System.FilePath
src/System/Console/Hawk/Interpreter.hs view
@@ -1,10 +1,18 @@+{-# LANGUAGE CPP #-} -- | A wrapper around the hint library, specialized for Hawk usage. module System.Console.Hawk.Interpreter ( applyContext , runHawkInterpreter ) where -import Control.Monad+import Prelude hiding (fail)++import Control.Monad hiding (fail)+#if MIN_VERSION_base(4,12,0)+import Control.Monad.Fail (fail)+#else+import Prelude (fail)+#endif import Data.List import Language.Haskell.Interpreter
src/System/Console/Hawk/UserExpr/CanonicalExpr.hs view
@@ -1,5 +1,5 @@+{-# LANGUAGE CPP #-} module System.Console.Hawk.UserExpr.CanonicalExpr where- import qualified Data.ByteString.Lazy.Char8 as B
+ tests/inputs/0-100 view
@@ -0,0 +1,101 @@+0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100
+ tests/inputs/1-10 view
@@ -0,0 +1,10 @@+1+2+3+4+5+6+7+8+9+10
+ tests/inputs/1-12 view
@@ -0,0 +1,4 @@+1 2 3+4 5 6+7 8 9+10 11 12
+ tests/inputs/1-3 view
@@ -0,0 +1,3 @@+1+2+3
+ tests/inputs/1-6 view
@@ -0,0 +1,2 @@+1 2 3+4 5 6
+ tests/inputs/1-9 view
@@ -0,0 +1,3 @@+1 2 3+4 5 6+7 8 9
+ tests/inputs/1-9commas view
@@ -0,0 +1,3 @@+1,2,3+4,5,6+7,8,9
+ tests/inputs/1-9tabs view
@@ -0,0 +1,3 @@+1 2 3+4 5 6+7 8 9
+ tests/inputs/equation view
@@ -0,0 +1,1 @@+x1*y1*z1 + x2*y2*z2
+ tests/inputs/example.in view
@@ -0,0 +1,5 @@+foo+ bar1+ bar2+ baz+ bar3
+ tests/inputs/json view
@@ -0,0 +1,1 @@+{"code": 200, "message": "OK"}
+ tests/inputs/passwd view
@@ -0,0 +1,1 @@+root:x:0:0:root:/root:/bin/bash
+ tests/preludes/default/prelude.hs view
@@ -0,0 +1,4 @@+{-# LANGUAGE ExtendedDefaultRules, OverloadedStrings #-}+import Prelude+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.List as L
+ tests/preludes/moduleName/prelude.hs view
@@ -0,0 +1,2 @@+module MyPrelude where+t = take
+ tests/preludes/moduleNamedMain/prelude.hs view
@@ -0,0 +1,2 @@+module Main where+t = take
+ tests/preludes/noImplicitPrelude/prelude.hs view
@@ -0,0 +1,2 @@+{-# LANGUAGE NoImplicitPrelude #-}+hello = "hello"
+ tests/preludes/readme/prelude.hs view
@@ -0,0 +1,5 @@+{-# LANGUAGE ExtendedDefaultRules, OverloadedStrings #-}+import Prelude+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.List as L+takeLast n = reverse . take n . reverse
+ tests/preludes/set/prelude.hs view
@@ -0,0 +1,5 @@+{-# LANGUAGE ExtendedDefaultRules, OverloadedStrings #-}+import Prelude+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.List as L+import Data.Set