]> matita.cs.unibo.it Git - fireball-separation.git/blobdiff - ocaml/parser.ml
Parser.from_file, and p* problems moved to problems/p
[fireball-separation.git] / ocaml / parser.ml
index 9e0e809c36b83feadef56ea275abaa7d113df55c..a1a9d95a7dd85f91545009d81c132cfbc49676ef 100644 (file)
@@ -188,25 +188,16 @@ prerr_endline (s);
   aux' chr line in\r
  let _, name, div, conv, ps = List.fold_left aux ("#", "?", "", [], []) lines in\r
  let div_provided = div <> "" in\r
- let div = if div_provided then div else "BOT" in\r
+ let div = if div_provided then div else "xxxxxx" in\r
  let strs = [div] @ ps @ conv in\r
 \r
  (* parse' *)\r
  let (tms, free) = parse_many strs in\r
- (* Replace pacmans and bottoms *)\r
- let n_bot = try Util.index_of "BOT" free with Not_found -> min_int in\r
- let n_pac = try Util.index_of "PAC" free with Not_found -> min_int in\r
- let n_bomb = try Util.index_of "BOMB" free with Not_found -> min_int in\r
- let fix lev v =\r
-  if v = lev + n_bot then assert false\r
-   else if v = lev + n_pac then assert false\r
-    else if v = lev + n_bomb then assert false\r
-     else `Var(v,1) in (* 1 by default when variable not applied *)\r
  (* Fix arity *)\r
  let open Num in\r
  let rec aux lev : nf -> nf = function\r
  | `I((n,_), args) -> `I((n,1 + Listx.length args), Listx.map (fun t -> aux lev t) args)\r
- | `Var(n,_) -> fix lev n\r
+ | `Var(n,_) -> `Var(n,1)\r
  | `Lam(_,t) -> `Lam (true, aux (lev+1) t)\r
  | `Match _ | `N _ -> assert false in\r
 let all_tms = List.map (aux 0) (tms :> Num.nf list) in\r
@@ -232,3 +223,18 @@ let ps = List.map (
  ) ps in\r
  name, div, conv, ps, free\r
 ;;\r
+\r
+\r
+let from_file path =\r
+ let lines = ref [] in\r
+ let chan = open_in path in\r
+ let _ = try\r
+  while true; do\r
+    lines := input_line chan :: !lines\r
+  done\r
+ with End_of_file ->\r
+  close_in chan in\r
+ let txt = String.concat "\n" (List.rev !lines) in\r
+ let problems = Str.split (Str.regexp "\r?\n\r?\n\\#") txt in\r
+ List.map problem_of_string problems\r
+;;\r