module Text.Derp.Char
 ( oneOf, spaces, space, newline, tab
 , upper, lower, alphaNum, digit, hexDigit, octDigit
 , char, satisfy, string
 ) where

import Text.Derp -- hiding (xsR, xsL, xsIn, parens, parensIn
                 --        , amb, ambIn, sexp, sexpIn
                 --        )

import Text.Derp.Combinator
import Data.Char

token c = Token [c] [c]

oneOf :: [Char] -> Parser Char
oneOf s = foldr1 (<|>) (map char s)

-- noneOf

spaces :: Parser ()
spaces = skipMany space

space, newline, tab :: Parser Char
space = satisfy isSpace
newline = char '\n'
tab = char '\t'

upper, lower, alphaNum, letter, digit, hexDigit, octDigit :: Parser Char
upper = satisfy isUpper
lower = satisfy isLower
alphaNum = satisfy isAlphaNum
letter = satisfy isLetter
digit = satisfy isDigit
hexDigit = satisfy isHexDigit
octDigit = satisfy isOctDigit

char :: Char -> Parser Char
char c = ter [c] ==> head

-- anyChar

satisfy :: (Char -> Bool) -> Parser Char
satisfy f = oneOf (filter f [minBound .. maxBound])

string :: String -> Parser String
string s = foldr (\pc pcs -> pc <~> pcs ==> uncurry (:)) (eps []) (map char s)