progs/app7.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 26 Sep 2013 11:05:54 +0100
changeset 104 ffde837b1db1
parent 93 4794759139ea
child 169 57df3d7b4a25
permissions -rw-r--r--
updated
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)
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
    12
   def ~[S] (right : => Parser[I, S]) : Parser[I, (T, S)] = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 66
diff changeset
    13
      new SeqParser(this, right)
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
    14
}
7
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
73cf4406b773 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16