harp-0.4.3.4/0000755000000000000000000000000013660564416011013 5ustar0000000000000000harp-0.4.3.4/Setup.hs0000644000000000000000000000005613660564416012450 0ustar0000000000000000import Distribution.Simple main = defaultMain harp-0.4.3.4/LICENSE0000644000000000000000000000261613660564416012025 0ustar0000000000000000All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. harp-0.4.3.4/harp.cabal0000644000000000000000000000276413660564416012742 0ustar0000000000000000Name: harp Version: 0.4.3.4 License: BSD3 License-File: LICENSE Author: Niklas Broberg Maintainer: David Fox Stability: Experimental Category: Language Synopsis: HaRP allows pattern-matching with regular expressions Description: HaRP, or Haskell Regular Patterns, is a Haskell extension that extends the normal pattern matching facility with the power of regular expressions. This expressive power is highly useful in a wide range of areas, including text parsing and XML processing. Regular expression patterns in HaRP work over ordinary Haskell lists ([]) of arbitrary type. We have implemented HaRP as a pre-processor to ordinary Haskell. . For details on usage, please see the website. Homepage: https://github.com/seereason/harp Build-Type: Simple tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC==8.0.1, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.3, GHC==8.10.1 Cabal-Version: >= 1.10 source-repository head type: git location: https://github.com/seereason/harp.git Library Default-Language: Haskell2010 Build-Depends: base < 4.15 Exposed-modules: Harp.Match harp-0.4.3.4/Harp/0000755000000000000000000000000013660564416011705 5ustar0000000000000000harp-0.4.3.4/Harp/Match.hs0000644000000000000000000001033513660564416013277 0ustar0000000000000000----------------------------------------------------------------------------- -- | -- Module : Harp.Match -- Copyright : (c) Niklas Broberg 2004, -- License : BSD-style (see the file LICENSE.txt) -- -- Maintainer : Niklas Broberg, d00nibro@dtek.chalmers.se -- Stability : experimental -- Portability : portable -- -- Functions that simulate the behavior of regular patterns -- using a Match monad for parsing lists. ----------------------------------------------------------------------------- {-# LANGUAGE CPP #-} module Harp.Match ( Match -- Match e a , runMatch -- Match e a -> [e] -> Maybe a , baseMatch -- (a -> Maybe b) -> Match a (a, b) , manyMatch -- Match e a -> Match e [a] , gManyMatch -- Match e a -> Match e [a] , foldComp -- [[a] -> [a]] -> ([a] -> [a]) , unzip0, unzip1, unzip2, unzip3, unzip4, unzip5, unzip6, unzip7 , (+++) ) where #if MIN_VERSION_base(4,8,0) import Control.Monad (ap, liftM) #endif import Data.List (unzip3, unzip4, unzip5, unzip6, unzip7) -------------------------------------------------------------- -- | The Match monad newtype Match e a = Match ([e] -> [(a, [e])]) (+++) :: Match e a -> Match e a -> Match e a (Match f) +++ (Match g) = Match (\es -> let aes1 = f es aes2 = g es in aes1 ++ aes2) #if MIN_VERSION_base(4,8,0) instance Applicative (Match e) where (<*>) = ap pure = return instance Functor (Match e) where fmap = liftM #endif instance Monad (Match e) where return x = Match (\es -> [(x, es)]) (Match f) >>= k = Match (\es -> let aes = f es in concatMap help aes) where help (a, es) = let Match g = k a in g es mfail :: Match e a mfail = Match $ \_ -> [] runM :: Match e a -> [e] -> [a] runM (Match f) es = let aes = f es in map fst $ filter (null . snd) aes getElement :: Match e e getElement = Match $ \es -> case es of [] -> [] (x:xs) -> [(x,x:xs)] discard :: Match e () discard = Match $ \es -> case es of [] -> [] (_:xs) -> [((), xs)] runMatch :: Match e a -> [e] -> Maybe a runMatch m es = case runM m es of [] -> Nothing (a:_) -> Just a baseMatch :: (a -> Maybe b) -> Match a (a, b) baseMatch f = do e <- getElement case f e of Nothing -> mfail Just b -> do discard return (e, b) gManyMatch :: Match e a -> Match e [a] gManyMatch m = (do a <- m as <- gManyMatch m return (a:as)) +++ (return []) manyMatch :: Match e a -> Match e [a] manyMatch m = (return []) +++ (do a <- m as <- manyMatch m return (a:as)) foldComp :: [[a] -> [a]] -> ([a] -> [a]) foldComp = foldl (.) id unzip0 :: [()] -> () unzip0 = const () unzip1 :: [a] -> [a] unzip1 = id unzip2 :: [(a,b)] -> ([a],[b]) unzip2 = unzip {- data M e a = Element (e -> M e a) | Fail | Return a (M e a) instance Monad (M e) where return x = Return x Fail (Element f) >>= k = Element (\e -> f e >>= k) Fail >>= k = Fail (Return x m) >>= k = k x ++++ (m >>= k) infix 5 ++++ (++++) :: M e a -> M e a -> M e a Fail ++++ n = n m ++++ Fail = m Return x m ++++ n = Return x (m ++++ n) m ++++ Return x n = Return x (m ++++ n) Element f ++++ Element g = Element (\e -> f e ++++ g e) runM :: M e a -> [e] -> [a] runM (Element f) (e:es) = runM (f e) es runM (Element _) [] = [] runM Fail _ = [] runM (Return x m) [] = x : runM m [] runM (Return _ m) es = runM m es -- the continuation trick newtype Match e a = Match () instance Monad (Match e) where return x = Match (\k -> k x) (Match f) >>= k = Match (\h -> f (\a -> let Match g = k a in g h)) runMatch :: Match e a -> [e] -> [a] runMatch (Match f) = runM (f return) mfail :: Match e a mfail = Match $ \_ -> Fail -}