never executed always true always false
1 module Parse.State where
2
3
4 data State = State
5 { newline :: [Bool]
6 }
7
8
9 init :: State
10 init =
11 State
12 { newline = [False]
13 }
14
15
16 setNewline :: State -> State
17 setNewline state =
18 case newline state of
19 [] -> state
20 (_:rest) -> state { newline = (True:rest) }
21
22
23 pushNewlineContext :: State -> State
24 pushNewlineContext state =
25 state { newline = (False:(newline state)) }
26
27
28 popNewlineContext :: State -> State
29 popNewlineContext state =
30 case newline state of
31 [] -> state
32 (_:[]) -> state
33 (last:next:rest) -> state { newline = (last || next):rest }
34
35
36 sawNewline :: State -> Bool
37 sawNewline state =
38 case newline state of
39 [] -> False
40 (b:_) -> b