diff --git a/unittest/parser/dune b/unittest/parser/dune index 46dcbe1e..08c0e3e3 100644 --- a/unittest/parser/dune +++ b/unittest/parser/dune @@ -1,4 +1,5 @@ (tests (names p1) (flags :standard -open Sidekick_util -open Sidekick_parser) - (libraries sidekick.util sidekick.parser)) + (package sidekick-parser) + (libraries sidekick.util sidekick-parser)) diff --git a/unittest/parser/p1.expected b/unittest/parser/p1.expected index baa081a2..e3305f97 100644 --- a/unittest/parser/p1.expected +++ b/unittest/parser/p1.expected @@ -1,4 +1,13 @@ t1: f (g x) y -loc(t1): at line 0, column 0 - at line 0, column 9 -t2: let x := 1 in (f (f x 2)) -loc(t2): at line 0, column 0 - at line 0, column 21 +loc(t1): at line 1, column 0 - at line 1, column 9 +t2: let x := 1 in f (f x 2) +loc(t2): at line 1, column 0 - at line 1, column 22 +t3: let l := map f (list 1 2 3) in let l2 := rev l in = (rev l2) l +loc(t3): at line 1, column 1 - at line 1, column 61 +t4: let assm := ==> (is_foo p) (= (filter p l) nil) in true +loc(t4): at line 1, column 0 - at line 1, column 51 +t5: let + f := lam (x : int) (y : int) (z : bool). (= (+ x y) z) and + g := lam x. (f (f x)) in + is_g g +loc(t5): at line 1, column 0 - at line 1, column 84 diff --git a/unittest/parser/p1.ml b/unittest/parser/p1.ml index 46fc9339..6494c9ec 100644 --- a/unittest/parser/p1.ml +++ b/unittest/parser/p1.ml @@ -1,20 +1,24 @@ -module P = Parse_term +module P = Parse_util module A = Ast_term (* let () = Printexc.record_backtrace true *) +let () = Printexc.record_backtrace true let () = Printexc.register_printer (function - | Parser_comb.ParseError e -> Some (Parser_comb.Error.to_string e) + | P.Exn_parse_error e -> Some (P.Error.to_string e) | _ -> None) let test_str what s = - let t = P.of_string_exn s in - - Fmt.printf "%s: %a@." what A.pp_term t; - Fmt.printf "loc(%s): %a@." what A.pp_loc (A.loc t) + let t = P.term_of_string s in + match t with + | Ok t -> + Fmt.printf "%s: %a@." what A.pp_term t; + Fmt.printf "loc(%s): %a@." what Loc.pp (A.loc t) + | Error err -> + Fmt.printf "FAIL:@ error while parsing %S:@ %a@." what P.Error.pp err let () = test_str "t1" "f (g x) y" let () = test_str "t2" "let x:= 1 in f (f x 2)" @@ -23,5 +27,15 @@ let () = test_str "t3" {| let l := map f (list 1 2 3) in -let l2 := rev l in eq (rev l2) l +let l2 := rev l in rev l2 = l + |} + +let () = + test_str "t4" {|let assm := is_foo p ==> (filter p l = nil) in true + |} + +let () = + test_str "t5" + {|let f := fn (x y : int) (z:bool). ( x+ y) = z + and g := fn x. f (f x) in is_g g |}