Setepenre pushed to branch master at Stefan / Typer
Commits: e9d8852d by Pierre Delaunay at 2016-12-17T13:08:12-05:00 * src/lparse.ml: when an error occur during macro expansion (after getting the sexp but before pexp_parse) the generated sexp is printed
- - - - -
2 changed files:
- samples/inductive.typer - src/lparse.ml
Changes:
===================================== samples/inductive.typer ===================================== --- a/samples/inductive.typer +++ b/samples/inductive.typer @@ -103,11 +103,11 @@ type_ = Macro_ type-impl; type A | a Int;
-%type Pair t1 t2 -% | pair t1 t2; +type Pair (t1 : Type) (t2 : Type) + | pair t1 t2;
-%type Point t -% | point (x : t) (y : t); +type Point (t : Type) + | point (x : t) (y : t);
%get-first : (a : Type) => (b : Type) => Pair a b -> a; %get-second : (a : Type) => (b : Type) => Pair a b -> b;
===================================== src/lparse.ml ===================================== --- a/src/lparse.ml +++ b/src/lparse.ml @@ -711,7 +711,12 @@ and handle_macro_call ctx func args t = | v -> value_fatal (lexp_location func) v "Macros should return a Sexp" in
- let pxp = pexp_parse sxp in + let pxp = try pexp_parse sxp + with e -> + error dloc "An error occurred while expanding a macro"; + sexp_print sxp; + raise e in + check pxp t ctx
(* Identify Call Type and return processed call. *) @@ -873,6 +878,13 @@ and lexp_expand_macro macro_funct sargs ctx ot: value_type = (* Vint/Vstring/Vfloat might need to be converted to sexp *) vxp
+(* Print each generated decls *) +and sexp_decls_macro_print sxp_decls = + match sxp_decls with + | Node(Symbol (_, "_;_"), decls) -> + List.iter (fun sxp -> sexp_decls_macro_print sxp) decls + | e -> sexp_print e; print_string "\n" + and lexp_decls_macro (loc, mname) sargs ctx: (pdecl list * elab_context) = try let lxp, ltp = infer (Pvar (loc, mname)) ctx in
@@ -883,7 +895,13 @@ and lexp_decls_macro (loc, mname) sargs ctx: (pdecl list * elab_context) = | _ -> fatal loc ("Macro `" ^ mname ^ "` should return a sexp") in
(* read as pexp_declaraton *) - pexp_decls_all [decls], ctx + (try pexp_decls_all [decls], ctx + (* if an error occur print generated code to ease debugging *) + with e -> + error loc "An error occurred while expanding a macro"; + sexp_decls_macro_print decls; + raise e) + with e -> fatal loc ("Macro `" ^ mname ^ "`not found")
View it on GitLab: https://gitlab.com/monnier/typer/commit/e9d8852d83fa0d85e538636c6fe45342957f...
Afficher les réponses par date