diff -r 47f86885d481 -r e85600529ca5 scala/app7.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scala/app7.scala Sat Jun 15 09:11:11 2013 -0400 @@ -0,0 +1,16 @@ +abstract class Parser[I, T] { + def parse(ts: I): Set[(T, I)] + + def parse_all(ts: I) : Set[T] = + for ((head, tail) <- parse(ts); if (tail.isEmpty)) + yield head + + def || (right : => Parser[I, T]) : Parser[I, T] = + new AltParser(this, right) + def ==>[S] (f: => T => S) : Parser [I, S] = + new FunParser(this, f) + def ~[S] (right : => Parser[I, S]) : Parser[I, (T, S)] = + new SeqParser(this, right) +} + +