Commits

pchiusano committed 673ca44

commit only if consumed at least one token

  • Participants
  • Parent commits 74979cd
  • Branches error-reporting

Comments (0)

Files changed (1)

src/main/scala/nomo/Parser.scala

     }
   }
 
-  def commit[A](p: Parser[A]): Parser[A] = p mapResult { r => 
-    r.status match {
-      case Failure(e) => Error(e)
-      case r => r 
+  def commit[A](p: Parser[A]): Parser[A] = position.flatMap(pos => 
+    p mapResult { r => 
+      if (r.position == pos) r.status
+      else r.status match {
+        case Failure(e) => Error(e)
+        case r => r
+      }
     }
-  }
+  )
 
-  //object Cont[A,B](
-  //    f: (Input[F,I], Accumulator[I,X,U]) => Trampoline[(Parser[A], Accumulator[I,X,U])],
-  //    rest: Result[X,E,U,A] => Status[E,Parser[B]]) extends Parser[A] {
-
-  // case class Cont[A](
-  //   stack: List[Result[X,E,U,Any] => Parser[A]]
-  //   p: Parser[A]) extends Parser[A] 
-  //   
   case class Cont[A](
       f: (Input[F,I], Accumulator[I,X,U]) => Trampoline[(Parser[A], Accumulator[I,X,U])]) extends Parser[A] {
     def feed(i: Input[F,I], ann: Accumulator[I,X,U]): Trampoline[(Parser[A], Accumulator[I,X,U])] = f(i,ann)