Add more example combinators to the ParcSt2St demo.
Chris Pressey
1 year, 5 months ago
11 | 11 | |
12 | 12 | char x = pred (\c v -> if x == c then Just v else Nothing) |
13 | 13 | try c = alt c ok |
14 | fol f [] = ok | |
15 | fol f (c:cs) = seq (f c) (fol f cs) | |
16 | seqn = fol (id) | |
17 | str = fol (char) | |
14 | 18 | |
15 | 19 | -- Grammar |
16 | 20 | |
21 | 25 | bits = seq bit (many bit) |
22 | 26 | bitstring = seq bits (try (char 'B')) |
23 | 27 | docco = many (seq (many whitespace) bitstring) |
28 | keyword s st = seqn [many whitespace, str s, update $ \v -> (s:v)] st | |
29 | proggo = seqn $ map (keyword) ["while", "do", "that"] | |
24 | 30 | |
25 | 31 | -- Demo |
32 | ||
26 | 33 | test1 = docco $ Parsing "1110B 100B" 0 |
27 | 34 | test2 = docco $ Parsing "1110G 100B" 0 |
35 | test3 = proggo $ Parsing "while do that" [] |