X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fparser.ml;h=f9e7989176ce0402bf25c056124fa08c0ebe3433;hb=0197354468e40860a3a104b9ea5b68854a22cfca;hp=800322677a102f3aa324df8ddb35ca4daa6afcda;hpb=5664c5924f59c805c6e658698cc2fa535cab27f6;p=fireball-separation.git diff --git a/ocaml/parser.ml b/ocaml/parser.ml index 8003226..f9e7989 100644 --- a/ocaml/parser.ml +++ b/ocaml/parser.ml @@ -1,7 +1,7 @@ exception ParsingError of string;; let mk_app x y = Num.mk_app x y;; -let mk_lam x = `Lam(true, x);; +let mk_lam x g = `Lam(true, x, g);; let mk_var x = `Var(x, -666);; let isAlphaNum c = let n = Char.code c in @@ -74,18 +74,27 @@ let rec read_smt vars = | Some x, cs -> match strip_spaces cs with | [] -> false | c::_ -> c = '.' + in let rec read_garbage (bound, free) = function + | ',' :: cs -> + (match read_smt (bound,free) cs with + | Some [x], cs, (_, free) -> + let g, cs, free = read_garbage (bound,free) cs in x::g, cs, free + | _, _, _ -> raise (ParsingError "Garbage expected after ','")) + | cs -> [], cs, free in let read_lambda (bound, free) cs = ( match read_var (strip_spaces cs) with | Some varname, cs -> - let vars' = (varname::bound, free) in + let bound' = varname::bound in (match strip_spaces cs with | [] -> raise (ParsingError "Lambda expression incomplete") - | c::cs -> (if c = '.' then (match read_smt vars' cs with + | '.' :: cs -> (match read_smt (bound', free) cs with | None, _, _ -> raise (ParsingError "Lambda body expected") - | Some [x], y, (_, free) -> Some [mk_lam x], y, (bound, free) + | Some [t], cs, (_, free) -> + let g, cs, free = read_garbage (bound', free) (strip_spaces cs) in + Some [mk_lam t g], cs, (bound, free) | Some _, _, _ -> assert false - ) else raise (ParsingError "Expected `.` after variable in lambda") - )) + ) + | _::_ -> raise (ParsingError "Expected `.` after variable in lambda")) | _, _ -> assert false ) in let rec aux vars cs = match strip_spaces cs with @@ -93,7 +102,7 @@ let rec read_smt vars = | c::_ as x -> let tms, cs, vars = ( if c = '(' then read_pars vars x - else if c = ')' then (None, x, vars) + else if c = ')' || c = ',' then (None, x, vars) else if check_if_lambda x then read_lambda vars x else read_var' vars x) in match tms with @@ -180,7 +189,7 @@ let problem_of_string s = let rec aux lev : nf -> nf = function | `I((n,_), args) -> `I((n,(if lev = 0 then 0 else 1) + Listx.length args), Listx.map (aux lev) args) | `Var(n,_) -> fix lev n - | `Lam(_,t) -> `Lam (true, aux (lev+1) t) + | `Lam(_,t,g) -> `Lam (true, aux (lev+1) t, List.map (aux (lev+1)) g) | `Match _ | `N _ -> assert false in let all_tms = List.map (aux 0) (tms :> Num.nf list) in