progs/app7.scala
changeset 93 4794759139ea
parent 92 e85600529ca5
child 169 57df3d7b4a25
equal deleted inserted replaced
92:e85600529ca5 93:4794759139ea
       
     1 abstract class Parser[I, T] {
       
     2   def parse(ts: I): Set[(T, I)]
       
     3 
       
     4   def parse_all(ts: I) : Set[T] =
       
     5     for ((head, tail) <- parse(ts); if (tail.isEmpty)) 
       
     6       yield head
       
     7 
       
     8   def || (right : => Parser[I, T]) : Parser[I, T] = 
       
     9       new AltParser(this, right)
       
    10   def ==>[S] (f: => T => S) : Parser [I, S] = 
       
    11       new FunParser(this, f)
       
    12    def ~[S] (right : => Parser[I, S]) : Parser[I, (T, S)] = 
       
    13       new SeqParser(this, right)
       
    14 }
       
    15 
       
    16