equal
deleted
inserted
replaced
|
1 class SeqParser[I, T, S](p: => Parser[I, T], |
|
2 q: => Parser[I, S]) |
|
3 extends Parser[I, (T, S)] { |
|
4 def parse(sb: I) = |
|
5 for ((head1, tail1) <- p.parse(sb); |
|
6 (head2, tail2) <- q.parse(tail1)) |
|
7 yield ((head1, head2), tail2) |
|
8 } |
|
9 |
|
10 class AltParser[I, T](p: => Parser[I, T], |
|
11 q: => Parser[I, T]) |
|
12 extends Parser[I, T] { |
|
13 def parse(sb: I) = p.parse(sb) ++ q.parse(sb) |
|
14 } |
|
15 |
|
16 class FunParser[I, T, S](p: => Parser[I, T], f: T => S) |
|
17 extends Parser[I, S] { |
|
18 def parse(sb: I) = |
|
19 for ((head, tail) <- p.parse(sb)) |
|
20 yield (f(head), tail) |
|
21 } |
|
22 |
|
23 |