regex-tdfa-text-1.0.0.3/0000755000000000000000000000000012566614150013055 5ustar0000000000000000regex-tdfa-text-1.0.0.3/LICENSE0000644000000000000000000000301312566614150014057 0ustar0000000000000000This modile is under this "3 clause" BSD license: Copyright (c) 2007-2009, Christopher Kuklewicz Copyright (c) 2012, shelarcy 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. * The names of the contributors may not 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. regex-tdfa-text-1.0.0.3/regex-tdfa-text.cabal0000644000000000000000000000220712566614150017052 0ustar0000000000000000name: regex-tdfa-text Cabal-Version: >= 1.6 version: 1.0.0.3 synopsis: Text interface for regex-tdfa description: This provides text interface for regex-tdfa. . This should be part of regex-tdfa package. But my patches are not accepted yet. So, I made a separate package. If you are interested in my patches, see and . category: Text license: BSD3 license-file: LICENSE author: Chris Kuklewicz 2007-2009, shelarcy 2012 maintainer: shelarcy build-type: Simple source-repository head type: darcs location: http://hub.darcs.net/shelarcy/regex-tdfa-text library Build-Depends: base >= 3 && < 5,array,text,regex-base,regex-tdfa >= 1.1.1 Exposed-Modules: Text.Regex.TDFA.Text Text.Regex.TDFA.Text.Lazy Buildable: True Extensions: MultiParamTypeClasses Ghc-Options: -O2 regex-tdfa-text-1.0.0.3/Setup.lhs0000644000000000000000000000011412566614150014661 0ustar0000000000000000#!/usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain regex-tdfa-text-1.0.0.3/Text/0000755000000000000000000000000012566614150014001 5ustar0000000000000000regex-tdfa-text-1.0.0.3/Text/Regex/0000755000000000000000000000000012566614150015053 5ustar0000000000000000regex-tdfa-text-1.0.0.3/Text/Regex/TDFA/0000755000000000000000000000000012566614150015571 5ustar0000000000000000regex-tdfa-text-1.0.0.3/Text/Regex/TDFA/Text.hs0000644000000000000000000000720512566614150017055 0ustar0000000000000000{-| Module : Text.Regex.TDFA.Text Copyright : Chris Kuklewicz 2007-2009, shelarcy 2012 License : BSD-style (see the file LICENSE) Maintainer : shelarcy Stability : experimental Portability : GHC (uses text) This modules provides 'RegexMaker' and 'RegexLike' instances for using 'Text' with the TDFA backend ("Text.Regex.TDFA.NewDFA.Engine" and "Text.Regex.TDFA.NewDFA.Tester"). This exports instances of the high level API and the medium level API of 'compile','execute', and 'regexec'. -} module Text.Regex.TDFA.Text( Regex ,CompOption ,ExecOption ,compile ,execute ,regexec ) where import Data.Array((!),elems) import qualified Data.Text as T(Text,empty,take,drop,uncons,unpack) import Text.Regex.Base(RegexLike(..),RegexMaker(..),Extract(..),MatchArray,RegexContext(..)) import Text.Regex.Base.Impl(polymatch,polymatchM) import Text.Regex.TDFA.ReadRegex(parseRegex) import Text.Regex.TDFA.String() -- piggyback on RegexMaker for String import Text.Regex.TDFA.TDFA(patternToRegex) import Text.Regex.TDFA.Common(Regex(..),CompOption,ExecOption(captureGroups),Position) import Data.Maybe(listToMaybe) import Text.Regex.TDFA.NewDFA.Uncons(Uncons(uncons)) import qualified Text.Regex.TDFA.NewDFA.Engine as Engine(execMatch) import qualified Text.Regex.TDFA.NewDFA.Tester as Tester(matchTest) instance Extract T.Text where before = T.take; after = T.drop; empty = T.empty instance Uncons T.Text where {- INLINE uncons #-} uncons = T.uncons instance RegexContext Regex T.Text T.Text where match = polymatch matchM = polymatchM instance RegexMaker Regex CompOption ExecOption T.Text where makeRegexOptsM c e source = makeRegexOptsM c e (T.unpack source) {-# SPECIALIZE execMatch :: Regex -> Position -> Char -> T.Text -> [MatchArray] #-} execMatch :: Uncons text => Regex -> Position -> Char -> text -> [MatchArray] execMatch = Engine.execMatch {-# SPECIALIZE myMatchTest :: Regex -> T.Text -> Bool #-} myMatchTest :: Uncons text => Regex -> text -> Bool myMatchTest = Tester.matchTest instance RegexLike Regex T.Text where matchOnce r s = listToMaybe (matchAll r s) matchAll r s = execMatch r 0 '\n' s matchCount r s = length (matchAll r' s) where r' = r { regex_execOptions = (regex_execOptions r) {captureGroups = False} } matchTest = myMatchTest matchOnceText regex source = fmap (\ma -> let (o,l) = ma!0 in (before o source ,fmap (\ol -> (extract ol source,ol)) ma ,after (o+l) source)) (matchOnce regex source) matchAllText regex source = map (fmap (\ol -> (extract ol source,ol))) (matchAll regex source) compile :: CompOption -- ^ Flags (summed together) -> ExecOption -- ^ Flags (summed together) -> T.Text -- ^ The regular expression to compile -> Either String Regex -- ^ Returns: the compiled regular expression compile compOpt execOpt txt = case parseRegex (T.unpack txt) of Left err -> Left ("parseRegex for Text.Regex.TDFA.Text failed:"++show err) Right pattern -> Right (patternToRegex pattern compOpt execOpt) execute :: Regex -- ^ Compiled regular expression -> T.Text -- ^ Text to match against -> Either String (Maybe MatchArray) execute r txt = Right (matchOnce r txt) regexec :: Regex -- ^ Compiled regular expression -> T.Text -- ^ Text to match against -> Either String (Maybe (T.Text, T.Text, T.Text, [T.Text])) regexec r txt = case matchOnceText r txt of Nothing -> Right (Nothing) Just (pre,mt,post) -> let main = fst (mt!0) rest = map fst (tail (elems mt)) -- will be [] in Right (Just (pre,main,post,rest)) regex-tdfa-text-1.0.0.3/Text/Regex/TDFA/Text/0000755000000000000000000000000012566614150016515 5ustar0000000000000000regex-tdfa-text-1.0.0.3/Text/Regex/TDFA/Text/Lazy.hs0000644000000000000000000001002412566614150017765 0ustar0000000000000000{-| Module : Text.Regex.TDFA.Text.Lazy Copyright : Chris Kuklewicz 2007-2009, shelarcy 2012 License : BSD-style (see the file LICENSE) Maintainer : shelarcy Stability : experimental Portability : GHC (uses text) This modules provides 'RegexMaker' and 'RegexLike' instances for using 'Text' with the TDFA backend ("Text.Regex.TDFA.NewDFA.Engine" and "Text.Regex.TDFA.NewDFA.Tester"). This exports instances of the high level API and the medium level API of 'compile','execute', and 'regexec'. -} module Text.Regex.TDFA.Text.Lazy( Regex ,CompOption ,ExecOption ,compile ,execute ,regexec ) where import Data.Array.IArray(Array,(!),elems,amap) import qualified Data.Text.Lazy as L(Text,empty,take,drop,uncons,unpack) import Text.Regex.Base(MatchArray,RegexContext(..),Extract(..),RegexMaker(..),RegexLike(..)) import Text.Regex.Base.Impl(polymatch,polymatchM) import Text.Regex.TDFA.ReadRegex(parseRegex) import Text.Regex.TDFA.String() -- piggyback on RegexMaker for String import Text.Regex.TDFA.TDFA(patternToRegex) import Text.Regex.TDFA.Common(Regex(..),CompOption,ExecOption(captureGroups),Position) import Data.Maybe(listToMaybe) import Text.Regex.TDFA.NewDFA.Uncons(Uncons(uncons)) import qualified Text.Regex.TDFA.NewDFA.Engine as Engine(execMatch) import qualified Text.Regex.TDFA.NewDFA.Tester as Tester(matchTest) instance Extract L.Text where before = L.take . toEnum; after = L.drop . toEnum; empty = L.empty instance RegexContext Regex L.Text L.Text where match = polymatch matchM = polymatchM instance Uncons L.Text where {- INLINE uncons #-} uncons = L.uncons instance RegexMaker Regex CompOption ExecOption L.Text where makeRegexOptsM c e source = makeRegexOptsM c e (L.unpack source) {-# SPECIALIZE execMatch :: Regex -> Position -> Char -> L.Text -> [MatchArray] #-} execMatch :: Uncons text => Regex -> Position -> Char -> text -> [MatchArray] execMatch = Engine.execMatch {-# SPECIALIZE myMatchTest :: Regex -> L.Text -> Bool #-} myMatchTest :: Uncons text => Regex -> text -> Bool myMatchTest = Tester.matchTest instance RegexLike Regex L.Text where matchOnce r s = listToMaybe (matchAll r s) matchAll r s = execMatch r 0 '\n' s matchCount r s = length (matchAll r' s) where r' = r { regex_execOptions = (regex_execOptions r) {captureGroups = False} } matchTest = myMatchTest matchOnceText regex source = fmap (\ ma -> let (o,l) = ma!0 in (before o source ,fmap (\ ol -> (extract ol source,ol)) ma ,after (o+l) source)) (matchOnce regex source) matchAllText regex source = let go :: Int -> L.Text -> [Array Int (Int, Int)] -> [Array Int (L.Text, (Int, Int))] go i _ _ | i `seq` False = undefined go _i _t [] = [] go i t (x:xs) = let (off0,len0) = x!0 trans pair@(off,len) = (extract (off-i,len) t,pair) t' = after (off0+(len0-i)) t in fmap trans x : seq t' (go (off0+len0) t' xs) in go 0 source (matchAll regex source) compile :: CompOption -- ^ Flags (summed together) -> ExecOption -- ^ Flags (summed together) -> L.Text -- ^ The regular expression to compile -> Either String Regex -- ^ Returns: the compiled regular expression compile compOpt execOpt txt = case parseRegex (L.unpack txt) of Left err -> Left ("parseRegex for Text.Regex.TDFA.Text.Lazy failed:"++show err) Right pattern -> Right (patternToRegex pattern compOpt execOpt) execute :: Regex -- ^ Compiled regular expression -> L.Text -- ^ Text to match against -> Either String (Maybe MatchArray) execute r txt = Right (matchOnce r txt) regexec :: Regex -- ^ Compiled regular expression -> L.Text -- ^ Text to match against -> Either String (Maybe (L.Text, L.Text, L.Text, [L.Text])) regexec r txt = case matchOnceText r txt of Nothing -> Right (Nothing) Just (pre,mt,post) -> let main = fst (mt!0) rest = map fst (tail (elems mt)) -- will be [] in Right (Just (pre,main,post,rest))