Commits

Sébastien Ferré committed d3c74b8

[dcg] bug fix about iterations

Comments (0)

Files changed (1)

 (* repetitions, favoring longest ones *)
 class ['ctx, 'elt, 'cursor] many (parse : ('ctx,'elt,'cursor) parse) (ctx : 'ctx) (cursor : 'cursor) =
   object (self)
-    val mutable state = `Loop (ctx, cursor, [], parse ctx cursor, `End)
+    val mutable state = `Loop (ctx, cursor, [], parse ctx cursor, `End), []
 
     method next =
       match state with
-	| `Loop (ctx, cursor, rev_le, p, state1) ->
+	| (`Loop (ctx, cursor, rev_le, p, loop1) as loop), msgs1 ->
 	  ( match p # next with
 	    | Parsed (ctx1, elt, cursor1) ->
-	        state <- `Loop (ctx1, cursor1, elt::rev_le, parse ctx1 cursor1, state);
+	        state <- `Loop (ctx1, cursor1, elt::rev_le, parse ctx1 cursor1, loop), msgs1;
 	        self # next
-	    | Failed _msgs ->
-	        state <- state1;
+	    | Failed msgs ->
+	        state <- loop1, union_msgs msgs msgs1;
 	        Parsed (ctx, List.rev rev_le, cursor) )
-	| `End -> Failed []
+	| `End, msgs -> Failed msgs
   end
 
 let many = new many
 (* non-empty repetitions with separators, favoring longest repetitions *)
 class ['ctx, 'elt, 'sep, 'cursor] list1 (p_elt : ('ctx,'elt,'cursor) parse) (p_sep : ('ctx,'sep,'cursor) parse) (ctx : 'ctx) (cursor : 'cursor) =
   object (self)
-    val mutable state = `Elt (ctx, cursor, [], p_elt ctx cursor, `End)
+    val mutable state = `Elt (ctx, cursor, [], p_elt ctx cursor, `End), []
 
     method next =
       match state with
-	| `Elt (ctx, cursor, rev_le, p, state1) ->
+	| (`Elt (ctx, cursor, rev_le, p, loop1) as loop), msgs1 ->
 	  ( match p # next with
 	    | Parsed (ctx1, e, cursor1) ->
-	        state <- `Sep (ctx1, cursor1, e::rev_le, p_sep ctx1 cursor1, state);
+	        state <- `Sep (ctx1, cursor1, e::rev_le, p_sep ctx1 cursor1, loop), msgs1;
 	        self # next
-	    | Failed _msgs ->
-	        state <- state1;
+	    | Failed msgs ->
+	        state <- loop1, union_msgs msgs msgs1;
 	        self # next )
-	| `Sep (ctx, cursor, rev_le, p, state1) ->
+	| (`Sep (ctx, cursor, rev_le, p, loop1) as loop), msgs1 ->
 	  ( match p # next with
 	    | Parsed (ctx1, _, cursor1) ->
-	        state <- `Elt (ctx1, cursor1, rev_le, p_elt ctx1 cursor1, state);
+	        state <- `Elt (ctx1, cursor1, rev_le, p_elt ctx1 cursor1, loop), msgs1;
 	        self # next
-	    | Failed _msgs ->
-	        state <- state1;
+	    | Failed msgs ->
+	        state <- loop1, union_msgs msgs msgs1;
 	        Parsed (ctx, List.rev rev_le, cursor) )
-	| `End -> Failed []
+	| `End, msgs -> Failed msgs
   end
 
 let list1 p_elt p_sep = new list1 p_elt p_sep (* p_elt |> fun x -> list1_aux p_elt p_sep --> (fun xs -> x::xs) *)