-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parc.hs
34 lines (26 loc) · 799 Bytes
/
Parc.hs
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
module Parc where
data ParseState = Parsing String
| Failure
deriving (Show, Ord, Eq)
type Parser = (ParseState -> ParseState)
ok :: ParseState -> ParseState
ok p = p
fail :: ParseState -> ParseState
fail p = Failure
pred :: (Char -> Bool) -> ParseState -> ParseState
pred _ Failure = Failure
pred _ (Parsing []) = Failure
pred f (Parsing (c:cs)) = if f c then (Parsing cs) else Failure
seq :: Parser -> Parser -> ParseState -> ParseState
seq p q s = case p s of
Failure -> Failure
other -> q other
alt :: Parser -> Parser -> ParseState -> ParseState
alt p q s = case p s of
Failure -> q s
other -> other
many :: Parser -> ParseState -> ParseState
many p s = case p s of
Failure -> s
Parsing [] -> Parsing []
other -> many p other