progs/app7.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 27 Oct 2013 14:17:55 +0000
changeset 164 6c1d214c39ef
parent 93 4794759139ea
child 169 57df3d7b4a25
permissions -rw-r--r--
added progs

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