app7.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 21 Nov 2012 02:20:16 +0000
changeset 66 9215b9fb8852
parent 7 73cf4406b773
child 70 e6868bd2942b
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     1
abstract class Parser[I, T] {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     2
  def parse(ts: I): Set[(T, I)]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     3
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     4
  def parse_all(ts: I) : Set[T] =
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     5
    for ((head, tail) <- parse(ts); if (tail.isEmpty)) 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     6
      yield head
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     7
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     8
  def || (right : => Parser[I, T]) : Parser[I, T] = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
     9
      new AltParser(this, right)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
    10
  def ==>[S] (f: => T => S) : Parser [I, S] = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
    11
      new FunParser(this, f)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
    12
}
7
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14