diff --git a/core/src/Streamly/Internal/Unicode/Char/Parser.hs b/core/src/Streamly/Internal/Unicode/Char/Parser.hs index 865fd44d4..051875030 100644 --- a/core/src/Streamly/Internal/Unicode/Char/Parser.hs +++ b/core/src/Streamly/Internal/Unicode/Char/Parser.hs @@ -14,11 +14,11 @@ module Streamly.Internal.Unicode.Char.Parser ( -- * Generic char - , charAnyCase + , charIgnoreCase -- * Sequences , string - , stringAnyCase + , stringIgnoreCase , dropSpace , dropSpace1 @@ -33,7 +33,7 @@ module Streamly.Internal.Unicode.Char.Parser , lower , upper , mark - , print + , printable , punctuation , separator , space @@ -43,7 +43,7 @@ module Streamly.Internal.Unicode.Char.Parser , digit , octDigit , hexDigit - , number + , numeric -- * Numeric , signed @@ -57,7 +57,6 @@ import Control.Applicative (Alternative(..)) import Control.Monad.Catch (MonadCatch) import Data.Bits (Bits, (.|.), shiftL) import Data.Char (ord) -import Prelude hiding (print) import Streamly.Internal.Data.Parser (Parser) import qualified Data.Char as Char @@ -77,7 +76,7 @@ import qualified Streamly.Internal.Data.Parser as Parser -- XXX It may be possible to implement faster predicates for ASCII byte stream. -- We can measure if there is a signficant difference and if so we can add such --- predicates to Streamly.Unicode.Char.Parser.Latin1. +-- predicates to Streamly.Unicode.Parser.Latin1. -- #define CHAR_PARSER_SIG(NAME) NAME :: MonadCatch m => Parser m Char Char -- XXX Need to use the predicates from Unicode.Char module/unicode-data package @@ -101,8 +100,8 @@ CHAR_PARSER(alpha,isAlpha) CHAR_PARSER_SIG(alphaNum) CHAR_PARSER(alphaNum,isAlphaNum) -CHAR_PARSER_SIG(print) -CHAR_PARSER(print,isPrint) +CHAR_PARSER_SIG(printable) +CHAR_PARSER(printable,isPrint) CHAR_PARSER_SIG(digit) CHAR_PARSER(digit,isDigit) @@ -119,8 +118,8 @@ CHAR_PARSER(letter,isLetter) CHAR_PARSER_SIG(mark) CHAR_PARSER(mark,isMark) -CHAR_PARSER_SIG(number) -CHAR_PARSER(number,isNumber) +CHAR_PARSER_SIG(numeric) +CHAR_PARSER(numeric,isNumber) CHAR_PARSER_SIG(punctuation) CHAR_PARSER(punctuation,isPunctuation) @@ -154,9 +153,9 @@ char c = Parser.satisfy (== c) -- XXX Case conversion may lead to change in number of chars -- | Match a specific character ignoring case. -{-# INLINE charAnyCase #-} -charAnyCase :: MonadCatch m => Char -> Parser m Char Char -charAnyCase c = Parser.lmap Char.toLower (Parser.satisfy (== Char.toLower c)) +{-# INLINE charIgnoreCase #-} +charIgnoreCase :: MonadCatch m => Char -> Parser m Char Char +charIgnoreCase c = Parser.lmap Char.toLower (Parser.satisfy (== Char.toLower c)) -------------------------------------------------------------------------------- -- Character sequences @@ -168,8 +167,8 @@ string = Parser.list -- XXX Not accurate unicode case conversion -- | Match the input with the supplied string and return it if successful. -stringAnyCase :: MonadCatch m => String -> Parser m Char String -stringAnyCase s = Parser.lmap Char.toLower (Parser.list (map Char.toLower s)) +stringIgnoreCase :: MonadCatch m => String -> Parser m Char String +stringIgnoreCase s = Parser.lmap Char.toLower (Parser.list (map Char.toLower s)) -- | Drop /zero/ or more white space characters. dropSpace :: MonadCatch m => Parser m Char () diff --git a/core/src/Streamly/Unicode/Parser.hs b/core/src/Streamly/Unicode/Parser.hs new file mode 100644 index 000000000..f8c9b21a9 --- /dev/null +++ b/core/src/Streamly/Unicode/Parser.hs @@ -0,0 +1,55 @@ +-- | +-- Module : Streamly.Unicode.Parser +-- Copyright : (c) 2021 Composewell Technologies +-- License : BSD-3-Clause +-- Maintainer : streamly@composewell.com +-- Stability : released +-- Portability : GHC +-- +-- To parse a text input, use the decode routines from +-- "Streamly.Unicode.Stream" module to convert an input byte stream to a +-- Unicode Char stream and then use these parsers on the Char stream. + +module Streamly.Unicode.Parser + ( + -- * Generic + char + , charIgnoreCase + + -- * Sequences + , string + , stringIgnoreCase + , dropSpace + , dropSpace1 + + -- * Classes + , alpha + , alphaNum + , letter + , ascii + , asciiLower + , asciiUpper + , latin1 + , lower + , upper + , mark + , printable + , punctuation + , separator + , space + , symbol + + -- * Digits + , digit + , octDigit + , hexDigit + , numeric + + -- * Numbers + , signed + , decimal + , hexadecimal + ) +where + +import Streamly.Internal.Unicode.Char.Parser diff --git a/core/streamly-core.cabal b/core/streamly-core.cabal index 6b9049a1b..c66bf9f54 100644 --- a/core/streamly-core.cabal +++ b/core/streamly-core.cabal @@ -357,6 +357,7 @@ library , Streamly.Data.Unfold , Streamly.Data.Array.Unboxed , Streamly.Data.Array.Unboxed.Mut + , Streamly.Unicode.Parser , Streamly.Unicode.Stream , Streamly.Unicode.String , Streamly.FileSystem.Handle diff --git a/streamly.cabal b/streamly.cabal index a705990c1..4dd32f400 100644 --- a/streamly.cabal +++ b/streamly.cabal @@ -229,6 +229,7 @@ extra-source-files: core/src/Streamly/Internal/Unicode/Char/Parser.hs core/src/Streamly/Internal/Unicode/Stream.hs core/src/Streamly/Internal/Unicode/String.hs + core/src/Streamly/Unicode/Parser.hs core/src/Streamly/Unicode/Stream.hs core/src/Streamly/Unicode/String.hs core/src/Streamly/Console/Stdio.hs