X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fparser.ml;h=570809dd6d4a6c952ee0139851bd97bef7be2af1;hb=a34071ed728b8de44b198de4e73a52207557ed81;hp=f5b7d7d1173097feffd36cf74bb14dbb921cff08;hpb=db562ac015ffc6c1a08c226b4eef7790b21661cd;p=fireball-separation.git diff --git a/ocaml/parser.ml b/ocaml/parser.ml index f5b7d7d..570809d 100644 --- a/ocaml/parser.ml +++ b/ocaml/parser.ml @@ -148,11 +148,13 @@ let _ = prerr_endline (">>>" ^ string_of_term (parse "(\\x. x y z z1 k) z1 z j") let n_bot = try Util.index_of "BOT" free with Not_found -> min_int in let n_pac = try Util.index_of "PAC" free with Not_found -> min_int in let n_bomb = try Util.index_of "BOMB" free with Not_found -> min_int in + let n_z = try Util.index_of "Z" free with Not_found -> min_int in let fix lev v = if v = lev + n_bot then `Bottom else if v = lev + n_pac then `Pacman else if v = lev + n_bomb then `Lam(true, `Bottom) - else `Var(v,1) in (* 1 by default when variable not applied *) + else if v = lev + n_z then `Var(lev, 0) (* FIXME why zero? *) + else `Var(v,1) in (* 1 by default when variable not applied *) (* Fix arity *) let open Num in let exclude_bottom = function @@ -173,12 +175,12 @@ 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 = "#" @@ -191,15 +193,19 @@ prerr_endline (s); 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 *) @@ -251,7 +257,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 @@ -260,6 +266,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 "\n\\$") txt in + let problems = Str.split (Str.regexp "[\n\r]+\\$") txt in List.map problem_of_string (List.tl (List.map ((^) "$") problems)) ;;