on master help sign in
Add simple predicated parsers
commita9ec10a658bcc1d73f9a6d6300d78d5d61c3ec06 authorAdithya Kumar <adithya@composewell.com> dateTue 5 Oct 2021, 17:12 (5 years ago) parent40d7516
2 files changed+83
src/Streamly/Internal/Unicode/Char/Parser.hs+82 streamly.cabal+1
src/Streamly/Internal/Unicode/Char/Parser.hsnew file+82
@@ -0,0 +1,82 @@
1+{-# LANGUAGE CPP #-}
2+
3+-- |
4+-- Module : Streamly.Internal.Unicode.Char.Parser
5+-- Copyright : (c) 2021 Composewell Technologies
6+--
7+-- License : BSD-3-Clause
8+-- Maintainer : streamly@composewell.com
9+-- Stability : experimental
10+-- Portability : GHC
11+--
12+module Streamly.Internal.Unicode.Char.Parser where
13+
14+import Control.Monad.Catch (MonadCatch)
15+import Streamly.Internal.Data.Parser (Parser)
16+
17+import qualified Data.Char as Char
18+import qualified Streamly.Internal.Data.Parser as Parser
19+
20+--------------------------------------------------------------------------------
21+-- Character classification
22+--------------------------------------------------------------------------------
23+
24+#define CHAR_PARSER_SIG(NAME) NAME :: MonadCatch m => Parser m Char Char
25+#define CHAR_PARSER(NAME, PREDICATE) NAME = Parser.satisfy Char.PREDICATE
26+
27+CHAR_PARSER_SIG(space)
28+CHAR_PARSER(space,isSpace)
29+
30+CHAR_PARSER_SIG(lower)
31+CHAR_PARSER(lower,isLower)
32+
33+CHAR_PARSER_SIG(upper)
34+CHAR_PARSER(upper,isUpper)
35+
36+CHAR_PARSER_SIG(alpha)
37+CHAR_PARSER(alpha,isAlpha)
38+
39+CHAR_PARSER_SIG(alphaNum)
40+CHAR_PARSER(alphaNum,isAlphaNum)
41+
42+CHAR_PARSER_SIG(print)
43+CHAR_PARSER(print,isPrint)
44+
45+CHAR_PARSER_SIG(digit)
46+CHAR_PARSER(digit,isDigit)
47+
48+CHAR_PARSER_SIG(octDigit)
49+CHAR_PARSER(octDigit,isOctDigit)
50+
51+CHAR_PARSER_SIG(hexDigit)
52+CHAR_PARSER(hexDigit,isHexDigit)
53+
54+CHAR_PARSER_SIG(letter)
55+CHAR_PARSER(letter,isLetter)
56+
57+CHAR_PARSER_SIG(mark)
58+CHAR_PARSER(mark,isMark)
59+
60+CHAR_PARSER_SIG(number)
61+CHAR_PARSER(number,isNumber)
62+
63+CHAR_PARSER_SIG(punctuation)
64+CHAR_PARSER(punctuation,isPunctuation)
65+
66+CHAR_PARSER_SIG(symbol)
67+CHAR_PARSER(symbol,isSymbol)
68+
69+CHAR_PARSER_SIG(separator)
70+CHAR_PARSER(separator,isSeparator)
71+
72+CHAR_PARSER_SIG(ascii)
73+CHAR_PARSER(ascii,isAscii)
74+
75+CHAR_PARSER_SIG(latin1)
76+CHAR_PARSER(latin1,isLatin1)
77+
78+CHAR_PARSER_SIG(asciiUpper)
79+CHAR_PARSER(asciiUpper,isAsciiUpper)
80+
81+CHAR_PARSER_SIG(asciiLower)
82+CHAR_PARSER(asciiLower,isAsciiLower)
streamly.cabal+1
@@ -485,6 +485,7 @@ library
485485 , Streamly.Internal.Unicode.Stream
486486 , Streamly.Internal.Unicode.Utf8
487487 , Streamly.Internal.Unicode.Char
488+ , Streamly.Internal.Unicode.Char.Parser
488489 , Streamly.Internal.Unicode.Array.Char
489490 , Streamly.Internal.Unicode.Array.Prim.Pinned
490491