-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Replaces/Enhances Text.Regex -- -- Interface API for regex-posix,pcre,parsec,tdfa,dfa @package regex-base @version 0.93 -- | Classes and instances for Regex matching. -- -- All the classes are declared here, and some common type aliases, and -- the MatchResult data type. -- -- The only instances here are for Extract String and Extract ByteString. -- There are no data values. The RegexContext instances are in -- Text.Regex.Base.Context, except for ones which run afoul of a -- repeated variable (RegexContext regex a a), which are defined in each -- modules' String and ByteString modules. module Text.Regex.Base.RegexLike -- | 0 based index from start of source, or (-1) for unused type MatchOffset = Int -- | non-negative length of a match type MatchLength = Int -- | 0 based array, with 0th index indicating the full match. If the full -- match location is not available, represent as (0,0). type MatchArray = Array Int (MatchOffset, MatchLength) type MatchText source = Array Int (source, (MatchOffset, MatchLength)) -- | This is the same as the type from JRegex. data MatchResult a MR :: a -> a -> a -> [a] -> Array Int a -> MatchResult a mrBefore :: MatchResult a -> a mrMatch :: MatchResult a -> a mrAfter :: MatchResult a -> a mrSubList :: MatchResult a -> [a] mrSubs :: MatchResult a -> Array Int a -- | Rather than carry them around spearately, the options for how to -- execute a regex are kept as part of the regex. There are two types of -- options. Those that can only be specified at compilation time and -- never changed are CompOpt. Those that can be changed later and affect -- how matching is performed are ExecOpt. The actually types for these -- depend on the backend. class RegexOptions regex compOpt execOpt | regex -> compOpt execOpt, compOpt -> regex execOpt, execOpt -> regex compOpt blankCompOpt :: (RegexOptions regex compOpt execOpt) => compOpt blankExecOpt :: (RegexOptions regex compOpt execOpt) => execOpt defaultCompOpt :: (RegexOptions regex compOpt execOpt) => compOpt defaultExecOpt :: (RegexOptions regex compOpt execOpt) => execOpt setExecOpts :: (RegexOptions regex compOpt execOpt) => execOpt -> regex -> regex getExecOpts :: (RegexOptions regex compOpt execOpt) => regex -> execOpt -- | RegexMaker captures the creation of the compiled regular expression -- from a source type and an option type. makeRegexM and -- makeRegexM report parse error using MonadError, -- usually (Either String regex). -- -- The makeRegex function has a default implementation that -- depends on makeRegexOpts and used defaultCompOpt and -- defaultExecOpt. Similarly for makeRegexM and -- makeRegexOptsM. -- -- There are also default implementaions for makeRegexOpts and -- makeRegexOptsM in terms of each other. So a minimal instance -- definition needs to only define one of these, hopefully -- makeRegexOptsM. class (RegexOptions regex compOpt execOpt) => RegexMaker regex compOpt execOpt source | regex -> compOpt execOpt, compOpt -> regex execOpt, execOpt -> regex compOpt makeRegex :: (RegexMaker regex compOpt execOpt source) => source -> regex makeRegexOpts :: (RegexMaker regex compOpt execOpt source) => compOpt -> execOpt -> source -> regex makeRegexM :: (RegexMaker regex compOpt execOpt source, Monad m) => source -> m regex makeRegexOptsM :: (RegexMaker regex compOpt execOpt source, Monad m) => compOpt -> execOpt -> source -> m regex -- | RegexLike is parametrized on a regular expression type and a source -- type to run the matching on. -- -- There are default implementations: matchTest and matchOnceText use -- matchOnce; matchCount and matchAllText use matchAll. matchOnce uses -- matchOnceText and matchAll uses matchAllText. So a minimal complete -- instance need to provide at least (matchOnce or matchOnceText) and -- (matchAll or matchAllText). Additional definitions are often provided -- where they will increase efficiency. -- --
--   [ c | let notVowel = makeRegex "[^aeiou]" :: Regex, c <- ['a'..'z'], matchTest notVowel [c]  ]
--   
--   "bcdfghjklmnpqrstvwxyz"
--   
-- -- The strictness of these functions is instance dependent. class (Extract source) => RegexLike regex source matchOnce :: (RegexLike regex source) => regex -> source -> Maybe MatchArray matchAll :: (RegexLike regex source) => regex -> source -> [MatchArray] matchCount :: (RegexLike regex source) => regex -> source -> Int matchTest :: (RegexLike regex source) => regex -> source -> Bool matchAllText :: (RegexLike regex source) => regex -> source -> [MatchText source] matchOnceText :: (RegexLike regex source) => regex -> source -> Maybe (source, MatchText source, source) -- | RegexContext is the polymorphic interface to do matching. Since -- target is polymorphic you may need to suply the type -- explicitly in contexts where it cannot be inferred. -- -- The monadic matchM version uses fail to report when the -- regex has no match in source. Two examples: -- -- Here the contest Bool is inferred: -- --
--   [ c | let notVowel = makeRegex "[^aeiou]" :: Regex, c <- ['a'..'z'], match notVowel [c]  ]
--   
--   "bcdfghjklmnpqrstvwxyz"
--   
-- -- Here the context '[String]' must be supplied: -- --
--   let notVowel = (makeRegex "[^aeiou]" :: Regex )
--   in do { c <- ['a'..'z'] ; matchM notVowel [c] } :: [String]
--   
--   ["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"]
--   
class (RegexLike regex source) => RegexContext regex source target match :: (RegexContext regex source target) => regex -> source -> target matchM :: (RegexContext regex source target, Monad m) => regex -> source -> m target -- | Extract allows for indexing operations on String or ByteString. class Extract source before :: (Extract source) => Int -> source -> source after :: (Extract source) => Int -> source -> source empty :: (Extract source) => source extract :: (Extract source) => (Int, Int) -> source -> source -- | Used in results of RegexContext instances newtype AllSubmatches f b AllSubmatches :: (f b) -> AllSubmatches f b getAllSubmatches :: AllSubmatches f b -> (f b) -- | Used in results of RegexContext instances newtype AllTextSubmatches f b AllTextSubmatches :: (f b) -> AllTextSubmatches f b getAllTextSubmatches :: AllTextSubmatches f b -> (f b) -- | Used in results of RegexContext instances newtype AllMatches f b AllMatches :: (f b) -> AllMatches f b getAllMatches :: AllMatches f b -> (f b) -- | Used in results of RegexContext instances newtype AllTextMatches f b AllTextMatches :: (f b) -> AllTextMatches f b getAllTextMatches :: AllTextMatches f b -> (f b) instance Extract (Seq a) instance Extract ByteString instance Extract ByteString instance Extract String -- | This is a module of instances of RegexContext (defined in -- Text.Regex.Base.RegexLike). Nothing else is exported. This is usually -- imported via the Text.Regex.Base convenience package which itself is -- re-exported from newer Text.Regex.XXX modules provided by the -- different regex-xxx backends. -- -- These instances work for all the supported types and backends -- interchangably. These instances provide the different results that can -- be gotten from a match or matchM operation (often via the =~ -- and =~~ operators with combine makeRegex with -- match and matchM respectively). This module name is -- Context because they operators are context dependent: use them in a -- context that expects an Int and you get a count of matches, use them -- in a Bool context and get True if there is a match, etc. -- -- RegexContext a b c takes a regular expression suppied in a -- type a generated by RegexMaker and a target text -- supplied in type b to a result type c using the -- match class function. The matchM class function works -- like match unless there is no match found, in which case it -- calls fail in the (arbitrary) monad context. -- -- There are a few type synonyms from RegexLike that are used here: -- --
--    
--   -- | 0 based index from start of source, or (-1) for unused
--   type MatchOffset = Int
--   -- | non-negative length of a match
--   type MatchLength = Int
--   type MatchArray = Array Int (MatchOffset, MatchLength)
--   type MatchText source = Array Int (source, (MatchOffset, MatchLength))
--   
-- -- There are also a few newtypes that used to prevent any possible -- overlap of types, which were not needed for GHC's late overlap -- detection but are needed for use in Hugs. -- --
--   newtype AllSubmatches f b = AllSubmatches {getAllSubmatches :: (f b)}
--   newtype AllTextSubmatches f b = AllTextSubmatches {getAllTextSubmatches :: (f b)}
--   newtype AllMatches f b = AllMatches {getAllMatches :: (f b)}
--   newtype AllTextMatches f b = AllTextMatches {getAllTextMatches :: (f b) }
--   
-- -- The newtypes' f parameters are the containers, usually -- [] or Array Int, (where the arrays all have lower -- bound 0). -- -- The two *Submatches newtypes return only information on the first -- match. The other two newtypes return information on all the -- non-overlapping matches. The two *Text* newtypes are used to mark -- result types that contain the same type as the target text. -- -- Where provided, noncaptured submatches will have a -- MatchOffset of (-1) and non-negative otherwise. The semantics -- of submatches depend on the backend and its compile and execution -- options. Where provided, MatchLength will always be -- non-negative. Arrays with no elements are returned with bounds of -- (1,0). Arrays with elements will have a lower bound of 0. -- -- XXX THIS HADDOCK DOCUMENTATION IS OUT OF DATE XXX -- -- These are for finding the first match in the target text: -- -- RegexContext a b Bool : Whether there is any match or not. -- -- RegexContext a b () : Useful as a guard with -- matchM or =~~ in a monad, since failure to match -- calls fail. -- -- RegexContext a b b : This returns the text of the whole -- match. It will return empty from the Extract type class -- if there is no match. These are defined in each backend module, but -- documented here for convenience. -- -- RegexContext a b (MatchOffset,MatchLength) : This returns -- the initial index and length of the whole match. MatchLength will -- always be non-negative, and 0 for a failed match. -- -- RegexContext a b (MatchResult b) : The MatchResult -- structure with details for the match. This is the structure copied -- from the old JRegex pacakge. -- -- RegexContext a b (b, b, b) : The text before the match, the -- text of the match, the text after the match -- -- RegexContext a b (b, MatchText b, b) : The text before the -- match, the details of the match, and the text after the match -- -- RegexContext a b (b, b, b, [b]) : The text before the -- match, the text of the match, the text after the match, and a list of -- the text of the 1st and higher sub-parts of the match. This is the -- same return value as used in the old Text.Regex API. -- -- Two containers of the submatch offset information: -- -- RegexContext a b MatchArray : Array of -- (MatchOffset,MatchLength) for all the sub matches. The whole -- match is at the intial 0th index. Noncaptured submatches will have a -- MatchOffset of (-1) The array will have no elements and -- bounds (1,0) if there is no match. -- -- RegexContext a b (AllSubmatches [] (MatchOffset,MatchLength) -- : List of (MatchOffset,MatchLength) The whole match is -- the first element, the rest are the submatches (if any) in order. The -- list is empty if there is no match. -- -- Two containers of the submatch text and offset information: -- --
--   RegexContext a b (AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength)))
--   
-- --
--   RegexContext a b (AllTextSubmatches [] (b, (MatchOffset, MatchLength)))
--   
-- -- Two containers of the submatch text information: -- --
--   RegexContext a b (AllTextSubmatches [] b)
--   
-- --
--   RegexContext a b (AllTextSubmatches (Array Int) b)
--   
-- -- These instances are for all the matches (non-overlapping). Note that -- backends are supposed to supply RegexLike instances for which -- the default matchAll and matchAllText stop searching -- after returning any successful but empty match. -- -- RegexContext a b Int : The number of matches, non-negative. -- -- Two containers for locations of all matches: -- --
--   RegexContext a b (AllMatches [] (MatchOffset, MatchLength))
--   
-- --
--   RegexContext a b (AllMatches (Array Int) (MatchOffset,MatchLength))
--   
-- -- Two containers for the locations of all matches and their submatches: -- -- RegexContext a b [MatchArray] : -- --
--   RegexContext a b (AllMatches (Array Int) MatchArray)
--   
-- -- Two containers for the text and locations of all matches and their -- submatches: -- --
--   RegexContext a b [MatchText b]
--   
-- --
--   RegexContext a b (AllTextMatches (Array Int) (MatchText b))
--   
-- -- Two containers for text of all matches: RegexContext a b -- (AllTextMatches [] b) -- --
--   RegexContext a b (AllTextMatches (Array Int) b)
--   
-- -- Four containers for text of all matches and their submatches: -- --
--   RegexContext a b [[b]]
--   
-- --
--   RegexContext a b (AllTextMatches (Array Int) [b])
--   
-- --
--   RegexContext a b (AllTextMatches [] (Array Int b))
--   
-- --
--   RegexContext a b (AllTextMatches (Array Int) (Array Int b))
--   
-- -- Unused matches are empty (defined via Extract) module Text.Regex.Base.Context instance (RegexLike a b) => RegexContext a b (AllTextMatches (Array Int) (Array Int b)) instance (RegexLike a b) => RegexContext a b (AllTextMatches [] (Array Int b)) instance (RegexLike a b) => RegexContext a b (AllTextMatches (Array Int) [b]) instance (RegexLike a b) => RegexContext a b [[b]] instance (RegexLike a b) => RegexContext a b (AllTextMatches (Array Int) b) instance (RegexLike a b) => RegexContext a b (AllTextMatches [] b) instance (RegexLike a b) => RegexContext a b (AllTextMatches (Array Int) (MatchText b)) instance (RegexLike a b) => RegexContext a b [MatchText b] instance (RegexLike a b) => RegexContext a b (AllMatches (Array Int) MatchArray) instance (RegexLike a b) => RegexContext a b [MatchArray] instance (RegexLike a b) => RegexContext a b (AllMatches (Array Int) (MatchOffset, MatchLength)) instance (RegexLike a b) => RegexContext a b (AllMatches [] (MatchOffset, MatchLength)) instance (RegexLike a b) => RegexContext a b (AllTextSubmatches (Array Int) b) instance (RegexLike a b) => RegexContext a b (AllTextSubmatches [] b) instance (RegexLike a b) => RegexContext a b (AllTextSubmatches [] (b, (MatchOffset, MatchLength))) instance (RegexLike a b) => RegexContext a b (AllTextSubmatches (Array Int) (b, (MatchOffset, MatchLength))) instance (RegexLike a b) => RegexContext a b (AllSubmatches [] (MatchOffset, MatchLength)) instance (RegexLike a b) => RegexContext a b MatchArray instance (RegexLike a b) => RegexContext a b (b, b, b, [b]) instance (RegexLike a b) => RegexContext a b (b, b, b) instance (RegexLike a b) => RegexContext a b (b, MatchText b, b) instance (RegexLike a b) => RegexContext a b (MatchResult b) instance (RegexLike a b) => RegexContext a b (MatchOffset, MatchLength) instance (RegexLike a b) => RegexContext a b Int instance (RegexLike a b) => RegexContext a b () instance (RegexLike a b) => RegexContext a b Bool -- | Classes and instances for Regex matching. -- -- This module merely imports and re-exports the common part of the new -- api: Text.Regex.Base.RegexLike and -- Text.Regex.Base.Context. -- -- To see what result types the instances of RegexContext can produce, -- please read the Text.Regex.Base.Context haddock documentation. -- -- This does not provide any of the backends, just the common interface -- they all use. The modules which provide the backends and their cabal -- packages are: -- -- -- -- In fact, just importing one of the backends is adequate, you do not -- also need to import this module. -- -- TODO: Copy Example*hs files into this haddock comment module Text.Regex.Base getVersion_Text_Regex_Base :: Version -- | Helper functions for defining certain instances of RegexContext. These -- help when defining instances of RegexContext with repeated types: -- --
--   instance (RegexLike regex source) => RegexContext regex source source where
--   
-- -- runs into overlapping restrictions. To avoid this I have each backend -- define, for its own Regex type: -- --
--   instance RegexContext Regex String String where
--     match = polymatch
--     matchM = polymatchM
--   
-- --
--   instance RegexContext Regex ByteString ByteString where
--     match = polymatch
--     matchM = polymatchM
--   
module Text.Regex.Base.Impl polymatch :: (RegexLike a b) => a -> b -> b polymatchM :: (RegexLike a b, Monad m) => a -> b -> m b