ascii-th 1.0.0.14 → 1.1.0.0
raw patch · 4 files changed
+126/−95 lines, 4 filesdep ~ascii-supersetPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: ascii-superset
API changes (from Hackage documentation)
Files
- ascii-th.cabal +2/−2
- changelog.md +7/−0
- library/ASCII/QuasiQuoters.hs +66/−36
- library/ASCII/TemplateHaskell.hs +51/−57
ascii-th.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0 name: ascii-th-version: 1.0.0.14+version: 1.1.0.0 synopsis: Template Haskell support for ASCII category: Data, Text @@ -29,7 +29,7 @@ ghc-options: -Wall build-depends: ascii-char ^>= 1.0- , ascii-superset ^>= 1.0.1+ , ascii-superset ^>= 1.1.0 , base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 library
changelog.md view
@@ -1,3 +1,10 @@+### 1.1.0.0 (2023-01-03)++Change `ascii-superset` version from 1.0 to 1.1++The constraints on the quasi-quotes and template-haskell splices have changed+accordingly with the changes to the classes as of ascii-superset-1.1.+ ### 1.0.0.14 (2023-01-02) Change test suite from `hedgehog` to `hspec`
library/ASCII/QuasiQuoters.hs view
@@ -1,5 +1,16 @@-module ASCII.QuasiQuoters ( char, string ) where+{-| +Use of these quasi-quoters in a pattern context requires the @ViewPatterns@+language extension.++-}+module ASCII.QuasiQuoters+ (+ char,+ string,+ )+ where+ import ASCII.Char (Char) import ASCII.Superset (toCharListMaybe, toCharMaybe) import ASCII.TemplateHaskell (isCharExp, isCharPat, isStringExp, isStringPat)@@ -12,59 +23,79 @@ import qualified Data.Char as Unicode import qualified Data.String as Unicode -{- | Produces an expression or a pattern corresponding to an ASCII character.+{-| An expression pattern corresponding to an ASCII character -The result will have an 'ASCII.Superset.CharSuperset' constraint; since this is polymorphic, use with a type signature to specify the particular you want is recommended.+=== In an expression context -The quasi-quoted string must consist of a single character that is within the ASCII character set.+The result will have a 'ASCII.Superset.FromChar' constraint. ->>> :set -XQuasiQuotes+The quasi-quoted string must consist of a single character that is within the+ASCII character set. ->>> [char|e|] :: ASCII.Char-SmallLetterE+@+[char|e|] == SmallLetterE ->>> [char|e|] :: Word8-101+[char|e|] == (101 :: Word8)+@ -Use in a pattern context requires enabling the @ViewPatterns@ language extension.+Since this is polymorphic, a type signature is recommended. ->>> :set -XViewPatterns+=== In a pattern context ->>> case Tilde of [char|@|] -> 1; [char|~|] -> 2; _ -> 3-2+The pattern matches a value of a type satisfying the 'ASCII.Superset.ToChar'+constraint. +@+let+ x = case Tilde of+ [char|@|] -> 1+ [char|~|] -> 2+ _ -> 3+in+ x == 2+@+ -} char :: QuasiQuoter char = expPatQQ requireOneAscii isCharExp isCharPat -{- | Produces an expression or a pattern corresponding to an ASCII string.+{- | An expression or pattern corresponding to an ASCII string -The result will have an 'ASCII.Superset.StringSuperset' constraint; since this is polymorphic, use with a type signature to specify the particular you want is recommended.+=== In an expression context -The quasi-quoted string must consist only of characters are within the ASCII character set.+The result will have a 'ASCII.Superset.FromString' constraint. ->>> :set -XQuasiQuotes+The quasi-quoted string must consist only of characters are within the ASCII+character set. ->>> [string|Hello!|] :: [ASCII.Char]-[CapitalLetterH,SmallLetterE,SmallLetterL,SmallLetterL,SmallLetterO,ExclamationMark]+@+[string|Hello!|] ==+ [CapitalLetterH,SmallLetterE,SmallLetterL,SmallLetterL,SmallLetterO,ExclamationMark] ->>> [string|Hello!|] :: Data.String.String-"Hello!"+[string|Hello!|] == ("Hello!" :: 'Data.String.String') ->>> [string|Hello!|] :: Data.Text.Text-"Hello!"+[string|Hello!|] == ("Hello!" :: 'Data.Text.Text') ->>> Data.ByteString.Builder.toLazyByteString [string|Hello!|]-"Hello!"+'Data.ByteString.Builder.toLazyByteString' [string|Hello!|] == "Hello!"+@ +Since this is polymorphic, a type signature is recommended. -Use in a pattern context requires enabling the @ViewPatterns@ language extension.+=== In a pattern context ->>> :set -XViewPatterns+The pattern matches a value of a type satisfying the 'ASCII.Superset.ToString'+constraint. ->>> case [CapitalLetterH, SmallLetterI] of [string|Bye|] -> 1; [string|Hi|] -> 2; _ -> 3-2+@+let+ x = case [CapitalLetterH, SmallLetterI] of+ [string|Bye|] -> 1+ [string|Hi|] -> 2+ _ -> 3+in+ x == 2+@ -} @@ -90,13 +121,12 @@ f || msg = \a -> case f a of Just b -> return b; Nothing -> fail msg expPatQQ :: (Unicode.String -> Q a) -> (a -> Q Exp) -> (a -> Q Pat) -> QuasiQuoter-expPatQQ f a b =- QuasiQuoter- { quoteExp = f >=> a- , quotePat = f >=> b- , quoteType = notType- , quoteDec = notDec- }+expPatQQ f a b = QuasiQuoter+ { quoteExp = f >=> a+ , quotePat = f >=> b+ , quoteType = notType+ , quoteDec = notDec+ } notType :: MonadFail m => a -> m b notType _ = fail "Cannot be used in a type context."
library/ASCII/TemplateHaskell.hs view
@@ -1,11 +1,11 @@-module ASCII.TemplateHaskell (-+module ASCII.TemplateHaskell+ ( {- * Characters -} charExp, charPat, {- * Character lists -} charListExp, charListPat, {- * Character supersets -} isCharExp, isCharPat,- {- * String supersets -} isStringExp, isStringPat-- ) where+ {- * String supersets -} isStringExp, isStringPat,+ )+ where import qualified ASCII.Char as ASCII import qualified ASCII.Superset as S@@ -20,104 +20,98 @@ pat :: Data a => a -> Q Pat pat = dataToPatQ (\_ -> Nothing) -{- |-->>> $(toCharOrFail 'F' >>= charExp)-CapitalLetterF+{-| ->>> $(toCharOrFail '\DEL' >>= charExp)-Delete+@+$(charExp CapitalLetterF) == CapitalLetterF+@ -} charExp :: ASCII.Char -> Q Exp charExp = exp -{- |-->>> :{->>> case SmallLetterS of->>> $(toCharOrFail 'r' >>= charPat) -> 1->>> $(toCharOrFail 's' >>= charPat) -> 2->>> _ -> 3->>> :}-2--This is the same as:+{-| ->>> :{->>> case SmallLetterS of->>> SmallLetterR -> 1->>> SmallLetterS -> 2->>> _ -> 3->>> :}-2+@+let+ x = case SmallLetterS of+ $(charPat SmallLetterR) -> 1+ $(charPat SmallLetterS) -> 2+ _ -> 3+in+ x == 2+@ -} charPat :: ASCII.Char -> Q Pat charPat = pat -{- |+{-| ->>> $(charListExp [CapitalLetterH, SmallLetterI])-[CapitalLetterH,SmallLetterI]+@+$(charListExp [CapitalLetterH, SmallLetterI]) == [CapitalLetterH, SmallLetterI]+@ -} charListExp :: [ASCII.Char] -> Q Exp charListExp = exp -{- |+{-| ->>> :{->>> case [CapitalLetterH, SmallLetterI] of->>> $(charListPat [CapitalLetterH, SmallLetterA]) -> 1->>> $(charListPat [CapitalLetterH, SmallLetterI]) -> 2->>> _ -> 3->>> :}-2+@+let+ x = case [CapitalLetterH, SmallLetterI] of+ $(charListPat [CapitalLetterH, SmallLetterA]) -> 1+ $(charListPat [CapitalLetterH, SmallLetterI]) -> 2+ _ -> 3+in+ x == 2+@ -} charListPat :: [ASCII.Char] -> Q Pat charListPat = pat -{- |+{-| Expression with a 'S.FromChar' constraint ->>> $(isCharExp CapitalLetterA) :: ASCII.Char-CapitalLetterA+@+$(isCharExp CapitalLetterA) == CapitalLetterA ->>> $(isCharExp CapitalLetterA) :: Word8-65+$(isCharExp CapitalLetterA) == (65 :: Word8) ->>> $(isCharExp CapitalLetterA) :: ASCII Word8-asciiUnsafe 65+$(isCharExp CapitalLetterA) == ('ASCII.Refinement.asciiUnsafe' 65 :: 'ASCII.Refinement.ASCII' Word8)+@ -} isCharExp :: ASCII.Char -> Q Exp isCharExp x = [| S.fromChar $(charExp x) |] -{- |-->>> :set -XViewPatterns+{-| Pattern that matches a type with a 'S.ToChar' constraint ->>> :{->>> case (66 :: Word8) of->>> $(isCharPat CapitalLetterA) -> 1->>> $(isCharPat CapitalLetterB) -> 2->>> _ -> 3->>> :}-2+@+let+ x = case (66 :: Word8) of+ $(isCharPat CapitalLetterA) -> 1+ $(isCharPat CapitalLetterB) -> 2+ _ -> 3+in+ x == 2+@ -} isCharPat :: ASCII.Char -> Q Pat isCharPat x = [p| (S.toCharMaybe -> Just $(charPat x)) |] +{-| Expression with a 'S.FromString' constraint -} isStringExp :: [ASCII.Char] -> Q Exp isStringExp xs = [| S.fromCharList $(charListExp xs) |] +{-| Pattern that matches a type with a 'S.ToString' constraint -} isStringPat :: [ASCII.Char] -> Q Pat isStringPat xs = [p| (S.toCharListMaybe -> Just $(charListPat xs)) |]