@@ -0,0 +1,82 @@
4+-- Module : Streamly.Internal.Unicode.Char.Parser
5+-- Copyright : (c) 2021 Composewell Technologies
7+-- License : BSD-3-Clause
8+-- Maintainer : streamly@composewell.com
9+-- Stability : experimental
12+module Streamly.Internal.Unicode.Char.Parser where
14+import Control.Monad.Catch (MonadCatch)
15+import Streamly.Internal.Data.Parser (Parser)
17+import qualified Data.Char as Char
18+import qualified Streamly.Internal.Data.Parser as Parser
20+--------------------------------------------------------------------------------
21+-- Character classification
22+--------------------------------------------------------------------------------
24+#define CHAR_PARSER_SIG(NAME) NAME :: MonadCatch m => Parser m Char Char
25+#define CHAR_PARSER(NAME, PREDICATE) NAME = Parser.satisfy Char.PREDICATE
27+CHAR_PARSER_SIG(space)
28+CHAR_PARSER(space,isSpace)
30+CHAR_PARSER_SIG(lower)
31+CHAR_PARSER(lower,isLower)
33+CHAR_PARSER_SIG(upper)
34+CHAR_PARSER(upper,isUpper)
36+CHAR_PARSER_SIG(alpha)
37+CHAR_PARSER(alpha,isAlpha)
39+CHAR_PARSER_SIG(alphaNum)
40+CHAR_PARSER(alphaNum,isAlphaNum)
42+CHAR_PARSER_SIG(print)
43+CHAR_PARSER(print,isPrint)
45+CHAR_PARSER_SIG(digit)
46+CHAR_PARSER(digit,isDigit)
48+CHAR_PARSER_SIG(octDigit)
49+CHAR_PARSER(octDigit,isOctDigit)
51+CHAR_PARSER_SIG(hexDigit)
52+CHAR_PARSER(hexDigit,isHexDigit)
54+CHAR_PARSER_SIG(letter)
55+CHAR_PARSER(letter,isLetter)
58+CHAR_PARSER(mark,isMark)
60+CHAR_PARSER_SIG(number)
61+CHAR_PARSER(number,isNumber)
63+CHAR_PARSER_SIG(punctuation)
64+CHAR_PARSER(punctuation,isPunctuation)
66+CHAR_PARSER_SIG(symbol)
67+CHAR_PARSER(symbol,isSymbol)
69+CHAR_PARSER_SIG(separator)
70+CHAR_PARSER(separator,isSeparator)
72+CHAR_PARSER_SIG(ascii)
73+CHAR_PARSER(ascii,isAscii)
75+CHAR_PARSER_SIG(latin1)
76+CHAR_PARSER(latin1,isLatin1)
78+CHAR_PARSER_SIG(asciiUpper)
79+CHAR_PARSER(asciiUpper,isAsciiUpper)
81+CHAR_PARSER_SIG(asciiLower)
82+CHAR_PARSER(asciiLower,isAsciiLower)