summaryrefslogtreecommitdiff
path: root/camlp4
diff options
context:
space:
mode:
authorXavier Clerc <xavier.clerc@inria.fr>2012-10-25 12:28:15 +0000
committerXavier Clerc <xavier.clerc@inria.fr>2012-10-25 12:28:15 +0000
commitb570a86fa735ada41475a189ad26a61d27f5a101 (patch)
tree121ff6e00d0742e0bfb9c15ea8f03a6aa6c36b87 /camlp4
parent0b37b273568cc9d64816494b882ee71098baf97d (diff)
downloadocaml-b570a86fa735ada41475a189ad26a61d27f5a101.tar.gz
PR#5119: camlp4 now raises a specific exception when 'DELETE_RULE' fails, rather than raising 'Not_found'
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13047 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'camlp4')
-rw-r--r--camlp4/Camlp4/Struct/Grammar/Delete.ml30
-rw-r--r--camlp4/Camlp4Parsers/Camlp4ListComprehension.ml2
-rw-r--r--camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml2
3 files changed, 30 insertions, 4 deletions
diff --git a/camlp4/Camlp4/Struct/Grammar/Delete.ml b/camlp4/Camlp4/Struct/Grammar/Delete.ml
index d8f9f9aa42..4273ebebf0 100644
--- a/camlp4/Camlp4/Struct/Grammar/Delete.ml
+++ b/camlp4/Camlp4/Struct/Grammar/Delete.ml
@@ -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 =
diff --git a/camlp4/Camlp4Parsers/Camlp4ListComprehension.ml b/camlp4/Camlp4Parsers/Camlp4ListComprehension.ml
index 7bdad3c4ec..f2216610f1 100644
--- a/camlp4/Camlp4Parsers/Camlp4ListComprehension.ml
+++ b/camlp4/Camlp4Parsers/Camlp4ListComprehension.ml
@@ -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";
diff --git a/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml b/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml
index 02c89f818d..85efa827e0 100644
--- a/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml
+++ b/camlp4/Camlp4Parsers/Camlp4OCamlReloadedParser.ml
@@ -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 ];