packages feed

irc-fun-messages-0.1.0.0: src/Network/IRC/Fun/Messages/Internal/Tokens/Other.hs

{- This file is part of irc-fun-messages.
 -
 - Written in 2015 by fr33domlover <fr33domlover@rel4tion.org>.
 -
 - ♡ Copying is an act of love. Please copy, reuse and share.
 -
 - The author(s) have dedicated all copyright and related and neighboring
 - rights to this software to the public domain worldwide. This software is
 - distributed without any warranty.
 -
 - You should have received a copy of the CC0 Public Domain Dedication along
 - with this software. If not, see
 - <http://creativecommons.org/publicdomain/zero/1.0/>.
 -}

module Network.IRC.Fun.Messages.Internal.Tokens.Other
    ( user
    , key
    , letter
    , digit
    , hexdigit
    , special
    )
where

import Data.Char (isAscii, isDigit)
import Network.IRC.Fun.Messages.Internal.Types
import Text.Regex.Applicative

user :: Regex UserName
user = some $ psym (`notElem` "\0\r\n @")

key :: Regex ChannelKey
key = some $ psym $ \ c -> isAscii c && c `notElem` "\0\r\n\f\t\v "

letter :: Regex Char
letter = psym $ \ c -> 'A' <= c && c <= 'Z'  ||  'a' <= c && c <= 'z'

digit :: Regex Char
digit = psym isDigit

hexdigit :: Regex Char
hexdigit = digit <|> upperhex
    where
    upperhex = psym $ \ c -> 'A' <= c && c <= 'F'

special :: Regex Char
special = psym (`elem` "[]\\`_^{|}")