(************************************************************ graphParser2.ml Created : Fri Jun 21 12:03:40 2002 Last modified: Fri Jun 21 13:21:55 2002 Compile: ocamlopt str.cmxa graphParser2.ml -o g # ************************************************************) (* 一行ずつ読み込んでテキスト処理 * 空行でおわり * *) let test_data = "a: b\nb: c d\nd: k\n" (*let line_regexp = Str.regexp "\([a-zA-Z0-9]\)+: *\(\([a-zA-Z0-9]\)+ +\)"*) type depend = Depend of string * (string list) let match_test line = match Str.split (Str.regexp ":") line with [] -> raise Not_found | t::f::[] -> begin match Str.split (Str.regexp " ") f with [] -> raise Not_found | lst -> Depend(t,lst) end | _ -> raise Not_found let _ = let rec f () = let data = read_line () in if data = "" then [] else data :: f () in List.iter (fun line -> match match_test line with Depend(t,lst) -> begin print_string (t^"\n"); List.iter (fun x -> print_string (x^" ")) lst; print_string "\n"; end) (f ())