parser3.scala
changeset 76 373cf55a3ca5
parent 64 2d625418c011
child 85 1a4065f965fb
equal deleted inserted replaced
75:898c25a4e399 76:373cf55a3ca5
     5   def parse(ts: I): Set[(T, I)]
     5   def parse(ts: I): Set[(T, I)]
     6 
     6 
     7   def parse_all(ts: I) : Set[T] =
     7   def parse_all(ts: I) : Set[T] =
     8     for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head
     8     for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head
     9 
     9 
       
    10   def parse_single(ts: I) : T = parse_all(ts).toList match {
       
    11     case t::Nil => t
       
    12     case _ => { println ("Parse Error") ; sys.exit(-1) }
       
    13   }
       
    14     
    10   def || (right : => Parser[I, T]) : Parser[I, T] = new AltParser(this, right)
    15   def || (right : => Parser[I, T]) : Parser[I, T] = new AltParser(this, right)
    11   def ==>[S] (f: => T => S) : Parser [I, S] = new FunParser(this, f)
    16   def ==>[S] (f: => T => S) : Parser [I, S] = new FunParser(this, f)
    12   def ~[S] (right : => Parser[I, S]) : Parser[I, (T, S)] = new SeqParser(this, right)
    17   def ~[S] (right : => Parser[I, S]) : Parser[I, (T, S)] = new SeqParser(this, right)
    13   def ~>[S] (right : => Parser[I, S]) : Parser[I, S] = this ~ right ==> (_._2)
    18   def ~>[S] (right : => Parser[I, S]) : Parser[I, S] = this ~ right ==> (_._2)
    14   def <~[S] (right : => Parser[I, S]) : Parser[I, T] = this ~ right ==> (_._1)
    19   def <~[S] (right : => Parser[I, S]) : Parser[I, T] = this ~ right ==> (_._1)