Fatal error: exception Invalid_argument("Str.matched_group")

149 views
Skip to first unread message

m4tej...@gmail.com

unread,
Sep 12, 2015, 10:05:07 PM9/12/15
to micmatch
Dear all,

I am happy mikmatch user, so thank you very much for this gem!

Today I noticed something that surprised me.

When I define this ugly function:

(* This is an artificial example which itself does not make much sense. *)
let rec count s =
  let rec loop subresult = function
  | "" -> subresult
  | RE bol ("01" | "02" | "03" | "04" | "05" | "06" | "07" | "08" | "09" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31" | "32") (_ * as rest) ->
      loop (succ subresult) rest
  | _ ->
      assert false
  in
  loop 0 s

and call it:

  Printf.printf "%d\n%!" (count "1307");

then, at runtime, I see the following exception:

  Fatal error: exception Invalid_argument("Str.matched_group")

Now, when I remove one of the alternatives in that huge regexp (e.g. "32"), the function behaves as expected. I.e., it prints:

  2

I would like to ask if this is known (limitation?) and what are the related to it.
(I've looked briefly to the manual, but I haven't find its explicit declaration).

Cordially,
--
Matej

Martin Jambon

unread,
Sep 12, 2015, 10:13:36 PM9/12/15
to micmatch
Hi,

It could be a limitation in the number of groups supported by the str regexp engine. I'm looking into it.


Martin
Reply all
Reply to author
Forward
0 new messages