summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/lib/Regex/regex003.hs
blob: 0aa51fe7aa965df436a86ab1ddc89a19386a0926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Text.Regex.Base
import Text.Regex.Posix(Regex,(=~),(=~~)) -- or DFA or PCRE or PosixRE
import qualified Data.ByteString.Char8 as B(ByteString,pack)

-- Show mixing of ByteString and String as well as polymorphism:

main = let x :: (RegexContext Regex String target) => target
           x = ("abaca" =~ B.pack "(.)a")
           x' :: (RegexContext Regex String target,Monad m) => m target
           x' = ("abaca" =~~ "(.)a")
           y :: (RegexContext Regex B.ByteString target) => target
           y = (B.pack "abaca" =~ "(.)a")
           y' :: (RegexContext Regex B.ByteString target,Monad m) => m target
           y' = (B.pack "abaca" =~~ B.pack "(.)a")
       in do print (x :: Bool)
             print (x :: Int)
             print (x :: [MatchArray])
             print (x' :: Maybe (String,String,String,[String]))
             print (y :: Bool)
             print (y :: Int)
             print (y :: [MatchArray])
             print (y' :: Maybe (B.ByteString,B.ByteString,B.ByteString,[B.ByteString]))

{- Output is, except for replacing Full with DFA (which has no capture)
True
2
[array (0,1) [(0,(1,2)),(1,(1,1))],array (0,1) [(0,(3,2)),(1,(3,1))]]
Just ("a","ba","ca",["b"])
True
2
[array (0,1) [(0,(1,2)),(1,(1,1))],array (0,1) [(0,(3,2)),(1,(3,1))]]
Just ("a","ba","ca",["b"])
-}
{- The output for DFA is
True
2
[array (0,0) [(0,(1,2))],array (0,0) [(0,(3,2))]]
Just ("a","ba","ca",[])
True
2
[array (0,0) [(0,(1,2))],array (0,0) [(0,(3,2))]]
Just ("a","ba","ca",[])
-}