regex-applicative-0.1: Regex-based parsing with applicative interface

MaintainerRoman Cheplyaka <>






data RE s a Source

Type of regular expressions that recognize symbols of type s and produce a result of type a.

Regular expressions can be built using Functor, Applicative and Alternative instances in the following natural way:

  • f <$> ra matches iff ra matches, and its return value is the result of applying f to the return value of ra.
  • pure x matches the empty string (i.e. it does not consume any symbols), and its return value is x
  • rf <*> ra matches a string iff it is a concatenation of two strings: one matched by rf and the other matched by ra. The return value is f a, where f and a are the return values of rf and ra respectively.
  • ra <|> rb matches a string which is accepted by either ra or rb. It is left-biased, so if both can match, the result of ra is used.
  • empty is a regular expression which does not match any string.
  • many ra matches concatenation of zero or more strings matched by ra and returns the list of ra's return values on those strings.


sym :: Eq s => s -> RE s sSource

Matches and returns the given symbol

psym :: (s -> Bool) -> RE s sSource

Matches and returns a single symbol which satisfies the predicate

anySym :: RE s sSource

Matches and returns any single symbol

reFoldl :: (b -> a -> b) -> b -> RE s a -> RE s bSource

Greedily matches zero or more symbols, which are combined using the given folding function

(=~) :: [s] -> RE s a -> Maybe aSource

Attempts to match a string of symbols against the regular expression