Permalink
Browse files

PR#5119: camlp4 now raises a specific exception when 'DELETE_RULE' fa…

…ils, rather than raising 'Not_found'

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13047 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent 0b37b27 commit b570a86fa735ada41475a189ad26a61d27f5a101 @xclerc xclerc committed Oct 25, 2012
View
@@ -9,6 +9,8 @@ Compilers:
Bug fixes:
- PR#4762: ?? is not used at all, but registered as a lexer token
- PR#4994: ocaml-mode doesn't work with xemacs21
+* PR#5119: camlp4 now raises a specific exception when 'DELETE_RULE' fails,
+ rather than raising 'Not_found'
- PR#5327: (Windows) Unix.select blocks if same socket listed in first and
third arguments
- PR#5468: ocamlbuild should preserve order of parametric tags
@@ -17,11 +17,37 @@
* - Nicolas Pouillard: refactoring
*)
+exception Rule_not_found of (string * string);
+
+let () =
+ Printexc.register_printer
+ (fun
+ [ Rule_not_found (symbols, entry) ->
+ let msg = Printf.sprintf "rule %S cannot be found in entry\n%s" symbols entry in
+ Some msg
+ | _ -> None ]) in ()
+;
+
module Make (Structure : Structure.S) = struct
module Tools = Tools.Make Structure;
module Parser = Parser.Make Structure;
+ module Print = Print.Make Structure;
open Structure;
+value raise_rule_not_found entry symbols =
+ let to_string f x =
+ let buff = Buffer.create 128 in
+ let ppf = Format.formatter_of_buffer buff in
+ do {
+ f ppf x;
+ Format.pp_print_flush ppf ();
+ Buffer.contents buff
+ } in
+ let entry = to_string Print.entry entry in
+ let symbols = to_string Print.print_rule symbols in
+ raise (Rule_not_found (symbols, entry))
+;
+
(* Deleting a rule *)
(* [delete_rule_in_tree] returns
@@ -104,7 +130,7 @@ value rec delete_rule_in_suffix entry symbols =
| None ->
let levs = delete_rule_in_suffix entry symbols levs in
[lev :: levs] ]
- | [] -> raise Not_found ]
+ | [] -> raise_rule_not_found entry symbols ]
;
value rec delete_rule_in_prefix entry symbols =
@@ -128,7 +154,7 @@ value rec delete_rule_in_prefix entry symbols =
| None ->
let levs = delete_rule_in_prefix entry symbols levs in
[lev :: levs] ]
- | [] -> raise Not_found ]
+ | [] -> raise_rule_not_found entry symbols ]
;
value rec delete_rule_in_level_list entry symbols levs =
@@ -102,7 +102,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
try do {
DELETE_RULE Gram expr: "["; sem_expr_for_list; "::"; expr; "]" END;
True
- } with [ Not_found -> False ];
+ } with [ Struct.Grammar.Delete.Rule_not_found _ -> False ];
value comprehension_or_sem_expr_for_list =
Gram.Entry.mk "comprehension_or_sem_expr_for_list";
@@ -40,7 +40,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
value revised =
try
(DELETE_RULE Gram expr: "if"; SELF; "then"; SELF; "else"; SELF END; True)
- with [ Not_found -> begin
+ with [ Struct.Grammar.Delete.Rule_not_found _ -> begin
DELETE_RULE Gram expr: "if"; SELF; "then"; expr LEVEL "top"; "else"; expr LEVEL "top" END;
DELETE_RULE Gram expr: "if"; SELF; "then"; expr LEVEL "top" END; False
end ];

0 comments on commit b570a86

Please sign in to comment.