regexpr 0.2.8 → 0.2.9
raw patch · 6 files changed
+16/−193 lines, 6 filesdep +mtlparse
Dependencies added: mtlparse
Files
- Hidden/ParseLib.hs +0/−89
- Hidden/ParseLibCore.hs +0/−97
- Hidden/ParseRegexStr.hs +2/−1
- Hidden/RegexPRCore.hs +2/−1
- Hidden/RegexPRTypes.hs +1/−1
- regexpr.cabal +11/−4
− Hidden/ParseLib.hs
@@ -1,89 +0,0 @@--- ParseLib.hs------ Author: Yoshikuni Jujo <PAF01143@nifty.ne.jp>-----{-# OPTIONS_GHC -fglasgow-exts #-}-{-# OPTIONS_GHC -fallow-undecidable-instances #-}--module Hidden.ParseLib (- module Hidden.ParseLibCore-, token-, tokenBack-, tokens-, tokensBack-, build-, repeatParse-, greedyRepeatParse--, optional-, greedyOptional-, list-, greedyList-, neList-, greedyNeList--, beginningOfInput-, endOfInput-, (>++>)-, (>:>)-) where--import Hidden.ParseLibCore ( Parse(runParse), MonadParse(..), MonadPlus(..) )-import Control.Monad( replicateM )------- token t recognises t as the first value in the input.----token, tokenBack :: (Eq a, MonadParse a m) => a -> m a-token x = spot (==x)-tokenBack x = spotBack (==x)--tokens, tokensBack :: (Eq a, MonadParse a m) => [a] -> m [a]-tokens = foldr (>:>) (return []) . map token-tokensBack = foldr (>:>) (return []) . map tokenBack--build :: Monad m => m a -> (a -> b) -> m b-build p f = p >>= return . f--repeatParse, greedyRepeatParse ::- MonadPlus m => Int -> Maybe Int -> m b -> m [b]-repeatParse mn (Just mx) p- | mn == mx = replicateM mn p- | mn < mx = replicateM mn p `mplus` (p >:> repeatParse mn (Just $ mx - 1) p)- | otherwise = error "minimal larger than maximal"-repeatParse mn Nothing p- = replicateM mn p `mplus` (p >:> repeatParse mn Nothing p)-greedyRepeatParse mn (Just mx) p- | mn == mx = replicateM mn p- | mn < mx = (p >:> greedyRepeatParse mn (Just $ mx - 1) p) `mplus`- replicateM mn p- | otherwise = error "minimal larger than maximal"-greedyRepeatParse mn Nothing p- = (p >:> greedyRepeatParse mn Nothing p) `mplus` replicateM mn p--optional, greedyOptional, list, greedyList, neList, greedyNeList ::- MonadPlus m => m a -> m [a]-optional = repeatParse 0 (Just 1)-greedyOptional = greedyRepeatParse 0 (Just 1)-list = repeatParse 0 Nothing-greedyList = greedyRepeatParse 0 Nothing-neList = repeatParse 1 Nothing-greedyNeList = greedyRepeatParse 1 Nothing---- beginning and end of input--beginningOfInput, endOfInput :: (MonadPlus m, MonadParse a m) => b -> m b-beginningOfInput x = do (pre,_) <- askHere- case pre of- [] -> return x- _ -> mzero-endOfInput x = do (_,post) <- askHere- case post of- [] -> return x- _ -> mzero--(>++>) :: Monad m => m [a] -> m [a] -> m [a]-m1 >++> m2 = do x <- m1; y <- m2; return $ x ++ y-(>:>) :: Monad m => m a -> m [a] -> m [a]-m1 >:> m2 = do x <- m1; y <- m2; return $ x : y
− Hidden/ParseLibCore.hs
@@ -1,97 +0,0 @@--- ParseLibCore.hs------ Author: Yoshikuni Jujo <PAF01143@nifty.ne.jp>-----{-# OPTIONS_GHC -fglasgow-exts #-}-{-# OPTIONS_GHC -fallow-undecidable-instances #-}--module Hidden.ParseLibCore (- Parse-, runParse-, MonadParse(spot, spotBack, still, parseNot, askHere, noBacktrack)-, MonadPlus(mzero, mplus)-, MonadReader(ask, local)-) where---- spot, spotBack, still, parseNot, return, (>>=), mzero, mplus, ask, local--import Control.Monad.Trans ( lift )-import Control.Monad ( MonadPlus(mzero, mplus) )-import Control.Monad.Reader( MonadReader(ask,local),- ReaderT(ReaderT, runReaderT), mapReaderT )-import Control.Monad.Writer( WriterT(WriterT, runWriterT), mapWriterT )-import Control.Monad.State ( StateT (StateT, runStateT ), mapStateT )-import Data.Monoid ( Monoid(mempty) )--class Monad m => MonadParse a m | m -> a where- spot :: (a -> Bool) -> m a- spotBack :: (a -> Bool) -> m a- still :: m b -> m b- parseNot :: c -> m b -> m c- askHere :: m ([a],[a])- noBacktrack :: m b -> m b--instance (MonadParse a m) => MonadParse a (ReaderT s m) where- spot = lift . spot- spotBack = lift . spotBack- still = mapReaderT still- parseNot x p = ReaderT $ \r -> parseNot x (runReaderT p r)- askHere = lift askHere- noBacktrack = mapReaderT noBacktrack--instance (MonadParse a m, Monoid w) => MonadParse a (WriterT w m) where- spot = lift . spot- spotBack = lift . spotBack- still = mapWriterT still- parseNot x p = WriterT $ parseNot (x, mempty) (runWriterT p)- askHere = lift askHere- noBacktrack = mapWriterT noBacktrack--instance (MonadParse a m) => MonadParse a (StateT r m) where- spot = lift . spot- spotBack = lift . spotBack- still = mapStateT still- parseNot x p = StateT $ \s -> parseNot (x,s) (runStateT p s)- askHere = lift askHere- noBacktrack = mapStateT noBacktrack--newtype Parse a b = Parse { runParse :: ([a],[a]) -> [(b,([a],[a]))] }------- instance of Monad MonadPlus MonadReader MonadParse-----instance MonadParse a (Parse a) where- spot = Parse . spt- where- spt p (pre,(x:xs))- | p x = [(x,(x:pre,xs))]- | otherwise = []- spt _ (_,[]) = []- spotBack = Parse . sptbck- where- sptbck p ((x:xs),post)- | p x = [(x,(xs,x:post))]- | otherwise = []- sptbck _ ([],_) = []- still p = Parse $ \inp -> do (ret,_) <- runParse p inp- return (ret,inp)- parseNot x (Parse p) = Parse $ \inp -> case p inp of- [] -> [(x,inp)]- _ -> []- askHere = ask- noBacktrack p = Parse $ (:[]) . head . runParse p--instance Monad (Parse a) where- return = Parse . \val inp -> [(val,inp)]- (Parse pr) >>= f- = Parse (\st -> concat [ runParse (f a) rest | (a,rest) <- pr st ])--instance MonadPlus (Parse a) where- mzero = Parse $ const []- Parse p1 `mplus` Parse p2 = Parse $ \inp -> p1 inp ++ p2 inp--instance MonadReader ([a],[a]) (Parse a) where- ask = Parse $ \inp -> [(inp,inp)]- local f m = Parse $ runParse m . f
Hidden/ParseRegexStr.hs view
@@ -13,7 +13,8 @@ getBR, modifyBR, setMode, setModes, getModes, isModeI, isModeM, isModeX )-import Hidden.ParseLib ( runParse, spot, token, tokens, mzero, mplus,+import Text.ParserCombinators.MTLParse.MTLParse+ ( runParse, spot, token, tokens, mzero, mplus, still, parseNot, endOfInput, MonadParse, MonadPlus, list, greedyNeList, optional )
Hidden/RegexPRCore.hs view
@@ -8,7 +8,8 @@ ) where import Hidden.RegexPRTypes ( RegexParser, MatchList, runRegexParser )-import Hidden.ParseLib ( spot, spotBack, still, noBacktrack, parseNot,+import Text.ParserCombinators.MTLParse.MTLParse+ ( spot, spotBack, still, noBacktrack, parseNot, build, tokens, tokensBack, repeatParse, greedyRepeatParse, beginningOfInput, endOfInput,
Hidden/RegexPRTypes.hs view
@@ -23,7 +23,7 @@ , runRegexParser ) where -import Hidden.ParseLib( Parse, runParse )+import Text.ParserCombinators.MTLParse.MTLParse( Parse, runParse ) import Control.Monad.State( StateT, runStateT, gets, modify ) import Control.Monad.Reader( ReaderT(runReaderT) ) import Hidden.Tools( modifySnd, modifyFst,
regexpr.cabal view
@@ -1,5 +1,5 @@ Name: regexpr-Version: 0.2.8+Version: 0.2.9 License: GPL License-File: LICENSE Author: Yoshikuni Jujo <PAF01143@nifty.ne.jp>@@ -14,8 +14,14 @@ . matchRegexPR :: String -> Maybe ((String, (String, String)), [(Int, String)]) .+ gmatchRegexPR :: String -> [((String, (String, String)), [(Int, String)])]+ .+ subRegexPR :: String -> String -> String+ . gsubRegexPR :: String -> String -> String .+ splitRegexPR :: String -> String -> [String]+ . Examples: . matchRegexPR "ab(cde)f\\1" "kkkabcdefcdefgh" =>@@ -33,12 +39,13 @@ . gmatchRegexPR "(?=(?<!(?!abc)))abc" "abcdefdefabc" => [(("abc", ("", "defdefabc")), []), (("abc", ("defdef", "")), [])]+ .+ splitRegexPR "\\s*,\\s*" "a,b ,c\t ,d , e" => ["a","b","c","d","e"] Category: Text-Build-Depends: base, mtl, HUnit+Build-Depends: base, mtl, HUnit, mtlparse Build-Type: Simple Exposed-modules: Text.RegexPR-Other-modules: Hidden.RegexPRTypes, Hidden.Tools, Hidden.ParseLib,- Hidden.ParseLibCore, Hidden.RegexPRCore,+Other-modules: Hidden.RegexPRTypes, Hidden.Tools, Hidden.RegexPRCore, Hidden.ParseRegexStr, Hidden.SrcRegActList, Hidden.TestMain Extra-source-files: TODO.ja.utf-8, localConfigure, BUGS.ja.utf-8