app7.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sat, 24 Nov 2012 14:58:41 +0000
changeset 78 a0e8c0cec402
parent 70 e6868bd2942b
permissions -rw-r--r--
added

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)
}