-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh24.hs
More file actions
38 lines (31 loc) · 760 Bytes
/
Ch24.hs
File metadata and controls
38 lines (31 loc) · 760 Bytes
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
{-# LANGUAGE OverloadedStrings #-}
module Ch24 where
import Text.Trifecta
stop :: Parser a
stop = unexpected "stop"
one = char '1'
one' = one >> stop
oneeof = one >> eof
onetwo = one >> char '2'
onetwo' = onetwo >> stop
onetwothree = string "123"
ex1 :: Parser Integer
ex1 = do {i <- integer; eof; return i}
testParser :: Show a => Parser a -> IO ()
testParser p = print $ parseString p mempty "123"
pNL s = putStrLn ('\n' : s)
main = do
pNL "stop==>"
testParser (stop :: Parser Char)
pNL "one==>"
testParser one
pNL "oneeof==>"
testParser oneeof
pNL "one'==>"
testParser (one' :: Parser Char)
pNL "onetwo==>"
testParser onetwo
pNL "onetwo'==>"
testParser (onetwo' :: Parser Char)
pNL "onetwothree==>"
testParser onetwothree