Commit 48411ba4 authored by Pietro Abate's avatar Pietro Abate

[r2006-09-09 20:16:08 by afrisch] Print regexp of the form [ t? ... ]

Original author: afrisch
Date: 2006-09-09 20:16:08+00:00
parent b480a9dd
......@@ -497,9 +497,12 @@ module Decompile(H : TABLE)(S : S) = struct
let s = slot n in
if not s.ok then (
s.ok <- true;
let (tr,f) = trans n in
if f then add_trans s final epsilon;
List.iter (fun (l,dst) -> add_trans s (conv dst) (rtrans l)) tr;
match trans n with
| `T (tr,f) ->
if f then add_trans s final epsilon;
List.iter (fun (l,dst) -> add_trans s (conv dst) (rtrans l)) tr
| `Eps (l,dst) ->
add_trans s (conv dst) (alt (rtrans l) epsilon)
);
s in
......
......@@ -26,5 +26,7 @@ end
module Decompile(X : TABLE)(S : S)
: sig
val decompile: (X.key -> (S.t * X.key) list * bool) -> X.key -> S.t regexp
val decompile: (X.key -> [ `T of (S.t * X.key) list * bool
| `Eps of S.t * X.key]
) -> X.key -> S.t regexp
end
......@@ -1544,8 +1544,26 @@ struct
let tr = Product.get t in
let tr = Product.clean_normal tr in
let tr = List.map (fun (l,t) -> prepare l, t) tr in
tr, Atoms.contains nil_atom t.atoms)
let eps = Atoms.contains nil_atom t.atoms in
let tr_cons = List.map (fun (li,ti) -> (cons li, cons ti)) tr in
try
let (l0,t0) = List.find
(fun ((l0,t0) as tr0) ->
let t'' =
List.fold_left
(fun accu ((li,ti) as tri) ->
if tr0 == tri then accu
else cup accu (times li ti)
)
(if eps then nil_type else empty)
tr_cons
in
equiv (descr t0) t'' ) tr_cons in
`Eps (prepare (descr l0), descr t0)
with Not_found ->
let tr = List.map (fun (l,t) -> prepare l, t) tr in
`T (tr, eps))
d
let gen = ref 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment