@@ -27,9 +27,11 @@ import Control.Lazy (fix)
27
27
import Control.Monad.State (gets , modify_ )
28
28
import Control.MonadPlus (guard , (<|>))
29
29
import Data.Array as Array
30
+ import Data.String.CodeUnits (toChar , singleton ) as CodeUnits
31
+ import Data.String.CodePoints (CodePoint , codePointFromChar )
30
32
import Data.Char (fromCharCode , toCharCode )
31
- import Data.Char .Unicode (isAlpha , isAlphaNum , isDecDigit , isHexDigit , isOctDigit , isSpace , isUpper , hexDigitToInt )
32
- import Data.Char .Unicode as Unicode
33
+ import Data.CodePoint .Unicode (isAlpha , isAlphaNum , isDecDigit , isHexDigit , isOctDigit , isSpace , isUpper , hexDigitToInt )
34
+ import Data.String .Unicode as Unicode
33
35
import Data.Either (Either (..))
34
36
import Data.Foldable (foldl , foldr )
35
37
import Data.Identity (Identity )
@@ -551,7 +553,7 @@ makeTokenParser (LanguageDef languageDef)
551
553
op :: Char -> Maybe Number -> Maybe Number
552
554
op _ Nothing = Nothing
553
555
op d (Just f) = do
554
- int' <- hexDigitToInt d
556
+ int' <- hexDigitToInt $ codePointFromChar d
555
557
pure $ ( f + toNumber int' ) / 10.0
556
558
557
559
exponent' :: ParserT String m Number
@@ -600,7 +602,7 @@ makeTokenParser (LanguageDef languageDef)
600
602
where
601
603
folder :: Maybe Int -> Char -> Maybe Int
602
604
folder Nothing _ = Nothing
603
- folder (Just x) d = ((base * x) + _) <$> hexDigitToInt d
605
+ folder (Just x) d = ((base * x) + _) <$> hexDigitToInt (codePointFromChar d)
604
606
605
607
-- ---------------------------------------------------------
606
608
-- Operators & reserved ops
@@ -657,7 +659,10 @@ makeTokenParser (LanguageDef languageDef)
657
659
Just { head: c, tail: cs } -> (caseChar c <?> msg) *> walk cs
658
660
659
661
caseChar :: Char -> ParserT String m Char
660
- caseChar c | isAlpha c = char (Unicode .toLower c) <|> char (Unicode .toUpper c)
662
+ caseChar c | isAlpha (codePointFromChar c)
663
+ , Just c1 <- CodeUnits .toChar (Unicode .toLowerSimple $ CodeUnits .singleton c)
664
+ , Just c2 <- CodeUnits .toChar (Unicode .toUpperSimple $ CodeUnits .singleton c) =
665
+ char c1 <|> char c2
661
666
| otherwise = char c
662
667
663
668
msg :: String
@@ -741,7 +746,7 @@ whiteSpace' langDef@(LanguageDef languageDef)
741
746
skipMany (simpleSpace <|> oneLineComment langDef <|> multiLineComment langDef <?> " " )
742
747
743
748
simpleSpace :: forall m . Monad m => ParserT String m Unit
744
- simpleSpace = skipMany1 (satisfy isSpace)
749
+ simpleSpace = skipMany1 (satisfyCP isSpace)
745
750
746
751
oneLineComment :: forall m . Monad m => GenLanguageDef String m -> ParserT String m Unit
747
752
oneLineComment (LanguageDef languageDef) =
@@ -780,31 +785,34 @@ inCommentSingle (LanguageDef languageDef) =
780
785
-- Helper functions that should maybe go in Text.Parsing.Parser.String --
781
786
-- -----------------------------------------------------------------------
782
787
783
- -- | Parse a digit. Matches any char that satisfies `Data.Char.Unicode.isDecDigit`.
788
+ satisfyCP :: forall m . Monad m => (CodePoint -> Boolean ) -> ParserT String m Char
789
+ satisfyCP p = satisfy (p <<< codePointFromChar)
790
+
791
+ -- | Parse a digit. Matches any char that satisfies `Data.CodePoint.Unicode.isDecDigit`.
784
792
digit :: forall m . Monad m => ParserT String m Char
785
- digit = satisfy isDecDigit <?> " digit"
793
+ digit = satisfyCP isDecDigit <?> " digit"
786
794
787
- -- | Parse a hex digit. Matches any char that satisfies `Data.Char .Unicode.isHexDigit`.
795
+ -- | Parse a hex digit. Matches any char that satisfies `Data.CodePoint .Unicode.isHexDigit`.
788
796
hexDigit :: forall m . Monad m => ParserT String m Char
789
- hexDigit = satisfy isHexDigit <?> " hex digit"
797
+ hexDigit = satisfyCP isHexDigit <?> " hex digit"
790
798
791
- -- | Parse an octal digit. Matches any char that satisfies `Data.Char .Unicode.isOctDigit`.
799
+ -- | Parse an octal digit. Matches any char that satisfies `Data.CodePoint .Unicode.isOctDigit`.
792
800
octDigit :: forall m . Monad m => ParserT String m Char
793
- octDigit = satisfy isOctDigit <?> " oct digit"
801
+ octDigit = satisfyCP isOctDigit <?> " oct digit"
794
802
795
- -- | Parse an uppercase letter. Matches any char that satisfies `Data.Char .Unicode.isUpper`.
803
+ -- | Parse an uppercase letter. Matches any char that satisfies `Data.CodePoint .Unicode.isUpper`.
796
804
upper :: forall m . Monad m => ParserT String m Char
797
- upper = satisfy isUpper <?> " uppercase letter"
805
+ upper = satisfyCP isUpper <?> " uppercase letter"
798
806
799
- -- | Parse a space character. Matches any char that satisfies `Data.Char .Unicode.isSpace`.
807
+ -- | Parse a space character. Matches any char that satisfies `Data.CodePoint .Unicode.isSpace`.
800
808
space :: forall m . Monad m => ParserT String m Char
801
- space = satisfy isSpace <?> " space"
809
+ space = satisfyCP isSpace <?> " space"
802
810
803
- -- | Parse an alphabetical character. Matches any char that satisfies `Data.Char .Unicode.isAlpha`.
811
+ -- | Parse an alphabetical character. Matches any char that satisfies `Data.CodePoint .Unicode.isAlpha`.
804
812
letter :: forall m . Monad m => ParserT String m Char
805
- letter = satisfy isAlpha <?> " letter"
813
+ letter = satisfyCP isAlpha <?> " letter"
806
814
807
815
-- | Parse an alphabetical or numerical character.
808
- -- | Matches any char that satisfies `Data.Char .Unicode.isAlphaNum`.
816
+ -- | Matches any char that satisfies `Data.CodePoint .Unicode.isAlphaNum`.
809
817
alphaNum :: forall m . Monad m => ParserT String m Char
810
- alphaNum = satisfy isAlphaNum <?> " letter or digit"
818
+ alphaNum = satisfyCP isAlphaNum <?> " letter or digit"
0 commit comments