module Text.ParserCombinators.Parsec.Char
( CharParser
, spaces, space
, newline, tab
, upper, lower, alphaNum, letter
, digit, hexDigit, octDigit
, char, string
, anyChar, oneOf, noneOf
, satisfy
) where
import Prelude
import Data.Char
import Text.ParserCombinators.Parsec.Pos( updatePosChar, updatePosString )
import Text.ParserCombinators.Parsec.Prim
type CharParser st a = GenParser Char st a
oneOf, noneOf :: [Char] -> CharParser st Char
oneOf cs = satisfy (\c -> elem c cs)
noneOf cs = satisfy (\c -> not (elem c cs))
spaces :: CharParser st ()
spaces = skipMany space <?> "white space"
space, newline, tab :: CharParser st Char
space = satisfy (isSpace) <?> "space"
newline = char '\n' <?> "new-line"
tab = char '\t' <?> "tab"
upper, lower, alphaNum, letter, digit, hexDigit, octDigit :: CharParser st Char
upper = satisfy (isUpper) <?> "uppercase letter"
lower = satisfy (isLower) <?> "lowercase letter"
alphaNum = satisfy (isAlphaNum) <?> "letter or digit"
letter = satisfy (isAlpha) <?> "letter"
digit = satisfy (isDigit) <?> "digit"
hexDigit = satisfy (isHexDigit) <?> "hexadecimal digit"
octDigit = satisfy (isOctDigit) <?> "octal digit"
char :: Char -> CharParser st Char
char c = satisfy (==c) <?> show [c]
anyChar :: CharParser st Char
anyChar = satisfy (const True)
satisfy :: (Char -> Bool) -> CharParser st Char
satisfy f = tokenPrim (\c -> show [c])
(\pos c cs -> updatePosChar pos c)
(\c -> if f c then Just c else Nothing)
string :: String -> CharParser st String
string s = tokens show updatePosString s