X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fparser.ml;h=60b59f9c4b35be19c82208d1c45982862240f382;hb=48099a8d17ed96681087fa7e7c507dc2ec209125;hp=379fb2edff3697e3e8c9740909223b1d705f61b6;hpb=032edbca0cd6654adae5b5f06620723e74847435;p=fireball-separation.git diff --git a/ocaml/parser.ml b/ocaml/parser.ml index 379fb2e..60b59f9 100644 --- a/ocaml/parser.ml +++ b/ocaml/parser.ml @@ -173,31 +173,37 @@ let _ = prerr_endline (">>>" ^ string_of_term (parse "(\\x. x y z z1 k) z1 z j") let problem_of_string s = prerr_endline (s); let lines = Str.split (Str.regexp "[\n\r\x0c\t;]+") s in - let lines = List.map String.trim lines in + (* let lines = List.map String.trim lines in *) let lines = List.filter ((<>) "") lines in prerr_endline("number of lines" ^ string_of_int (List.length lines)); let aux (last, name, div, conv, ps) line = let chr = String.sub line 0 1 in - let line = String.sub line 1 (String.length line - 1) in + let line = String.trim (String.sub line 1 (String.length line - 1)) in if line = "" then chr, name, div, conv, ps else let rec aux' chr line = if chr = "#" - then chr, line, div, conv, ps + then chr, name, div, conv, ps + else if chr = "$" + then "#", line, div, conv, ps else if chr = "D" then chr, name, line, conv, ps else if chr = "C" then chr, name, div, line::conv, ps else if chr = "N" then chr, name, div, conv, line::ps - else if last = "" - then raise (ParsingError ("Unexpected at beginning of problem: " ^ chr)) - else aux' last (chr ^ line) in + else if chr = " " + then aux' last line + else raise (ParsingError + ("Unexpected at beginning of problem: `" ^ chr ^ "` " ^ line)) in aux' chr line in - let _, name, div, conv, ps = List.fold_left aux ("#", "?", "", [], []) lines in + let _, name, div, conv, ps = List.fold_left aux ("#", "no label", "", [], []) lines in let div_provided = div <> "" in let div = if div_provided then div else "BOT" in let strs = [div] @ ps @ conv in + if strs = ["BOT"] + then raise (ParsingError "empty problem"); + (* parse' *) let (tms, free) = parse_many strs in (* Replace pacmans and bottoms *) @@ -249,7 +255,7 @@ let ps = List.map ( let from_file path = - let lines = ref [] in + let lines = ref [""] in let chan = open_in path in let _ = try while true; do @@ -258,6 +264,6 @@ let from_file path = with End_of_file -> close_in chan in let txt = String.concat "\n" (List.rev !lines) in - let problems = Str.split (Str.regexp "\r?\n\r?\n\\#") txt in - List.map problem_of_string problems + let problems = Str.split (Str.regexp "[\n\r\x0c\t]+\\$") txt in + List.map problem_of_string (List.tl (List.map ((^) "$") problems)) ;;