Regex-based parsing with applicative interface
|LTS Haskell 20.23:||0.3.4|
|Stackage Nightly 2023-05-29:||0.3.4|
|Latest on Hackage:||0.3.4|
Module documentation for 0.3.4
regex-applicative is a parsing combinator library for Haskell based on regular expressions.
import Text.Regex.Applicative data Protocol = HTTP | FTP deriving Show protocol :: RE Char Protocol protocol = HTTP <$ string "http" <|> FTP <$ string "ftp" type Host = String type Location = String data URL = URL Protocol Host Location deriving Show host :: RE Char Host host = many $ psym $ (/= '/') url :: RE Char URL url = URL <$> protocol <* string "://" <*> host <* sym '/' <*> many anySym main = print $ "http://stackoverflow.com/questions" =~ url
See the API reference.
For common tasks, this package is several times slower than monadic parser combinator libraries like parsec. However, this library has a roughly linear complexity, whereas monadic parser combinators have exponential worst-time complexity (see here).
Some tips to make your regex run faster:
If you don’t care about the result of the whole regex or its part, only whether it matches or not, mark it with
<$. Recognition is faster than parsing.
If you apply the same regex to multiple strings, partially apply it like so:
let matcher = match my_regex in map matcher my_strings
This way the compiled regex is stored in the
matchervalue and shared among the strings.
Only GHC versions >= 8.0 are supported, although older versions may work too.
- Let the user provide a custom
Make a release to refresh the haddocks on hackage (see https://github.com/feuerbach/regex-applicative/issues/35).
- Use strict left fold in decimal/hexadecimal
- Include a missing test module in the sdist tarball
- Fix the test suite
- Fix build with GHC 7.9
Fix the test suite
Port the test suite to tasty
- Add a new module,
Text.Regex.Applicative.Common, which contains some commonly used regexps (by Aleksey Khudyakov)
- Improve the test suite
- Add the
- Make matching functions a bit more lax
- Fix a bug in the
- Infix matching functions
- Improved documentation
- Improved performance
- Improved portability
- Expose Object interface
- Allow matching prefixes rather than the whole string
- Add non-greedy repetitions
- Completely rewrite the engine. Now it’s faster and runs in constant space.
- Add ‘string’ function and ‘IsString’ instance.
- Fix a .cabal-file issue introduced in 0.1.2
- Change the fixity of =~
- Relax the constraint on the containers version
- Fix a bug in ‘reFoldl’ and ‘many’
- “Lazy” infinite regexes are no longer supported
- Initial release