From: acondolu Date: Sat, 15 Jul 2017 13:31:04 +0000 (+0200) Subject: Fixes to parser X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=666a228779e465d08a0deea2e35c0cccf5722b40;p=fireball-separation.git Fixes to parser --- diff --git a/ocaml/parser.ml b/ocaml/parser.ml index f5b7d7d..60b59f9 100644 --- a/ocaml/parser.ml +++ b/ocaml/parser.ml @@ -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 = 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 +191,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 +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 @@ -260,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 "\n\\$") txt in + let problems = Str.split (Str.regexp "[\n\r\x0c\t]+\\$") txt in List.map problem_of_string (List.tl (List.map ((^) "$") problems)) ;; diff --git a/ocaml/problems.ml b/ocaml/problems.ml index bd3e880..f281277 100644 --- a/ocaml/problems.ml +++ b/ocaml/problems.ml @@ -1,6 +1,22 @@ open Lambda4;; open Util;; +(* Syntax for problem files in problem/ folder: + +- dollar ($) on newline + begin new problem + $! means that the problem is expected to be separable, + $? means that it is expected to be unseparable + +- (#) on new line + comment line + +- (D) (C) (N) stand respectively for divergent, convergent, numeric + +- lines starting with spaces inherit the type from the last line + +*) + let assert_separable x = match solve x with | _, `Separable _ -> () diff --git a/ocaml/problems/o b/ocaml/problems/o index 67fa90b..20d9808 100644 --- a/ocaml/problems/o +++ b/ocaml/problems/o @@ -1,10 +1,10 @@ $! o1 N x a b -x (_. BOT) c + x (_. BOT) c $! o2 N x (y (_. BOT) a) c -x (y a PAC) d + x (y a PAC) d $! o3 D y (x a1 BOMB c) (x BOMB b1 d) @@ -14,7 +14,7 @@ C y (x a2 BOMB c) (x BOMB b1 d) $! o4 D x BOMB a1 c -x y BOMB d + x y BOMB d $! o6 D x BOMB diff --git a/ocaml/problems/p b/ocaml/problems/p index 6f1e062..a2155a6 100644 --- a/ocaml/problems/p +++ b/ocaml/problems/p @@ -1,3 +1,4 @@ + $! p2 N x y x z