Giter VIP home page Giter VIP logo

regex-applicative's Introduction

regex-applicative

regex-applicative is a parsing combinator library for Haskell based on regular expressions.

Example

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

Documentation

See the API reference.

Performance

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:

  1. If you don't care about the result of the whole regex or its part, only whether it matches or not, mark it with void or <$. Recognition is faster than parsing.

  2. 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 matcher value and shared among the strings.

GHC support

Only GHC versions >= 8.0 are supported, although older versions may work too.

regex-applicative's People

Contributors

mitchellwrosen avatar phadej avatar shimuuar avatar strake avatar t0yv0 avatar unkindpartition avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.