]> matita.cs.unibo.it Git - fireball-separation.git/blobdiff - ocaml/parser.ml
Fixes to parser
[fireball-separation.git] / ocaml / parser.ml
index f5b7d7d1173097feffd36cf74bb14dbb921cff08..60b59f9c4b35be19c82208d1c45982862240f382 100644 (file)
@@ -173,12 +173,12 @@ let _ = prerr_endline (">>>" ^ string_of_term (parse "(\\x. x y z z1 k) z1 z j")
 let problem_of_string s =\r
 prerr_endline (s);\r
  let lines = Str.split (Str.regexp "[\n\r\x0c\t;]+") s in\r
- let lines = List.map String.trim lines in\r
+ (* let lines = List.map String.trim lines in *)\r
  let lines = List.filter ((<>) "") lines in\r
  prerr_endline("number of lines" ^ string_of_int (List.length lines));\r
  let aux (last, name, div, conv, ps) line =\r
   let chr = String.sub line 0 1 in\r
-  let line = String.sub line 1 (String.length line - 1) in\r
+  let line = String.trim (String.sub line 1 (String.length line - 1)) in\r
   if line = "" then chr, name, div, conv, ps else\r
   let rec aux' chr line =\r
    if chr = "#"\r
@@ -191,15 +191,19 @@ prerr_endline (s);
     then chr, name, div, line::conv, ps\r
    else if chr = "N"\r
     then chr, name, div, conv, line::ps\r
-   else if last = ""\r
-    then raise (ParsingError ("Unexpected at beginning of problem: " ^ chr))\r
-   else aux' last (chr ^ line) in\r
+   else if chr = " "\r
+    then aux' last line\r
+   else raise (ParsingError\r
+     ("Unexpected at beginning of problem: `" ^ chr ^ "` " ^ line)) in\r
   aux' chr line in\r
- let _, name, div, conv, ps = List.fold_left aux ("#", "?", "", [], []) lines in\r
+ let _, name, div, conv, ps = List.fold_left aux ("#", "no label", "", [], []) lines in\r
  let div_provided = div <> "" in\r
  let div = if div_provided then div else "BOT" in\r
  let strs = [div] @ ps @ conv in\r
 \r
+ if strs = ["BOT"]\r
+  then raise (ParsingError "empty problem");\r
+\r
  (* parse' *)\r
  let (tms, free) = parse_many strs in\r
  (* Replace pacmans and bottoms *)\r
@@ -251,7 +255,7 @@ let ps = List.map (
 \r
 \r
 let from_file path =\r
- let lines = ref [] in\r
+ let lines = ref [""] in\r
  let chan = open_in path in\r
  let _ = try\r
   while true; do\r
@@ -260,6 +264,6 @@ let from_file path =
  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 "\n\\$") txt in\r
+ let problems = Str.split (Str.regexp "[\n\r\x0c\t]+\\$") txt in\r
  List.map problem_of_string (List.tl (List.map ((^) "$") problems))\r
 ;;\r