try
while true do
let line = read_line () in
- if Str.string_match (Str.regexp " \([^ ]*\) -> \([^ ;]*\)\(\( \[.*\]\)?\);") line 0 then
+ if Str.string_match (Str.regexp " \\([^ ]*\\) -> \\([^ ;]*\\)\\(\\( \\[.*\\]\\)?\\);") line 0 then
let source = Str.matched_group 1 line in
let target = Str.matched_group 2 line in
- let rest = Str.matched_group 3 line in
- let tar =
- try
- search_node target
- with
- Not_found ->
- let tar = Node (target,ref []) in
- nodes := tar :: !nodes ;
- tar
- in
- let sou =
- try
- let sou = search_node source in
- let Node (_,ts) = sou in
- ts := tar::!ts ;
- sou
- with
- Not_found ->
- let sou = Node (source,ref [tar]) in
- nodes := sou :: !nodes ;
- sou
- in
- arcs := (sou,tar,rest)::!arcs
+ begin
+ if source <> target then
+ (* not a self loop *)
+ let rest = Str.matched_group 3 line in
+ let tar =
+ try
+ search_node target
+ with
+ Not_found ->
+ let tar = Node (target,ref []) in
+ nodes := tar :: !nodes ;
+ tar
+ in
+ let sou =
+ try
+ let sou = search_node source in
+ let Node (_,ts) = sou in
+ ts := tar::!ts ;
+ sou
+ with
+ Not_found ->
+ let sou = Node (source,ref [tar]) in
+ nodes := sou :: !nodes ;
+ sou
+ in
+ arcs := (sou,tar,rest)::!arcs
+ end
else
print_endline line
done