--- a/progs/app8.scala Wed Oct 30 03:36:10 2013 +0000
+++ b/progs/app8.scala Wed Oct 30 03:44:40 2013 +0000
@@ -1,3 +1,9 @@
+class AltParser[I, T](p: => Parser[I, T],
+ q: => Parser[I, T])
+ extends Parser[I, T] {
+ def parse(sb: I) = p.parse(sb) ++ q.parse(sb)
+}
+
class SeqParser[I, T, S](p: => Parser[I, T],
q: => Parser[I, S])
extends Parser[I, (T, S)] {
@@ -7,14 +13,8 @@
yield ((head1, head2), tail2)
}
-class AltParser[I, T](p: => Parser[I, T],
- q: => Parser[I, T])
- extends Parser[I, T] {
- def parse(sb: I) = p.parse(sb) ++ q.parse(sb)
-}
-
class FunParser[I, T, S](p: => Parser[I, T], f: T => S)
- extends Parser[I, S] {
+ extends Parser[I, S] {
def parse(sb: I) =
for ((head, tail) <- p.parse(sb))
yield (f(head), tail)