diff options
author | Nicolas Pouillard <np@nicolaspouillard.fr> | 2008-10-13 13:34:06 +0000 |
---|---|---|
committer | Nicolas Pouillard <np@nicolaspouillard.fr> | 2008-10-13 13:34:06 +0000 |
commit | 253a5f6364cb3f66274e9c7c5dcc332710e7e10d (patch) | |
tree | ab1a24e26e0bcb520308de51637c3f6aeadd9d81 | |
parent | 2b0441401a9686529cfe8d97cf73ecc09a51bef5 (diff) | |
download | ocaml-253a5f6364cb3f66274e9c7c5dcc332710e7e10d.tar.gz |
camlp4: Fix two toplevel bugs: PR#4495 and PR#4593 at once
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@9080 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | camlp4/Camlp4Top/Top.ml | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/camlp4/Camlp4Top/Top.ml b/camlp4/Camlp4Top/Top.ml index 8e683fcbcc..4b013c2db0 100644 --- a/camlp4/Camlp4Top/Top.ml +++ b/camlp4/Camlp4Top/Top.ml @@ -54,19 +54,29 @@ module Lexer = Camlp4.Struct.Lexer.Make Token; external not_filtered : 'a -> Gram.not_filtered 'a = "%identity"; +value initialization = lazy begin + if Sys.interactive.val + then Format.printf "\tCamlp4 Parsing version %s\n@." Camlp4_config.version + else () +end; + +value lookup x xs = try Some (List.assq x xs) with [ Not_found -> None ]; + value wrap parse_fun = - let token_stream_ref = ref None in + let token_streams = ref [] in + let cleanup lb = + try token_streams.val := List.remove_assq lb token_streams.val + with [ Not_found -> () ] + in fun lb -> + let () = Lazy.force initialization in let () = Register.iter_and_take_callbacks (fun (_, f) -> f ()) in let token_stream = - match token_stream_ref.val with + match lookup lb token_streams.val with [ None -> - let () = if Sys.interactive.val then - Format.printf "\tCamlp4 Parsing version %s\n@." Camlp4_config.version - else () in let not_filtered_token_stream = Lexer.from_lexbuf lb in let token_stream = Gram.filter (not_filtered not_filtered_token_stream) in - do { token_stream_ref.val := Some token_stream; token_stream } + do { token_streams.val := [ (lb,token_stream) :: token_streams.val ]; token_stream } | Some token_stream -> token_stream ] in try match token_stream with parser @@ -74,9 +84,8 @@ value wrap parse_fun = | [: :] -> parse_fun token_stream ] with [ End_of_file | Sys.Break | (Loc.Exc_located _ (End_of_file | Sys.Break)) - as x -> raise x + as x -> (cleanup lb; raise x) | x -> - let () = Stream.junk token_stream in let x = match x with [ Loc.Exc_located loc x -> do { @@ -86,6 +95,7 @@ value wrap parse_fun = | x -> x ] in do { + cleanup lb; Format.eprintf "@[<0>%a@]@." Camlp4.ErrorHandler.print x; raise Exit } ]; |