pax_global_header00006660000000000000000000000064127546472630014532gustar00rootroot0000000000000052 comment=454faf3553c5b6cc2d11116b9ab7046b6454f697 tophide-1.0.4/000077500000000000000000000000001275464726300131705ustar00rootroot00000000000000tophide-1.0.4/LICENSE000066400000000000000000000026051275464726300142000ustar00rootroot00000000000000Copyright (c) 2008 Martin Jambon All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tophide-1.0.4/META.in000066400000000000000000000002511275464726300142440ustar00rootroot00000000000000# specifications for "tophide": description = "Hiding toplevel _values" requires = "" archive(byte,toploop) = "tophide.cmo" archive(byte,create_toploop) = "tophide.cmo" tophide-1.0.4/Makefile000066400000000000000000000024121275464726300146270ustar00rootroot00000000000000# Copyright 2008 Martin Jambon. All rights reserved. # This file is distributed under the terms stated in file LICENSE. VERSION = 1.0.4 export VERSION .PHONY: all install clean all: META tophide.cmo tophide.cmo: tophide.ml ocamlc -I +compiler-libs -c tophide.ml install: ocamlfind install tophide META tophide.cmi tophide.cmo uninstall: ocamlfind remove tophide clean: rm -f *.cmo *.cmi META: META.in Makefile cat META.in > META echo 'version = "$(VERSION)"' >> META archive: rm -rf /tmp/tophide /tmp/tophide-$(VERSION) && \ cp -r . /tmp/tophide && \ cd /tmp/tophide && \ $(MAKE) clean && \ $(MAKE) META && \ rm -f *~ tophide*.tar* && \ cd /tmp && cp -r tophide tophide-$(VERSION) && \ tar czf tophide.tar.gz tophide && \ tar cjf tophide.tar.bz2 tophide && \ tar czf tophide-$(VERSION).tar.gz tophide-$(VERSION) && \ tar cjf tophide-$(VERSION).tar.bz2 tophide-$(VERSION) mv /tmp/tophide.tar.gz /tmp/tophide.tar.bz2 .. mv /tmp/tophide-$(VERSION).tar.gz /tmp/tophide-$(VERSION).tar.bz2 .. cp ../tophide.tar.gz ../tophide.tar.bz2 $$WWW/ cp ../tophide-$(VERSION).tar.gz ../tophide-$(VERSION).tar.bz2 $$WWW/ cp README $$WWW/tophide-readme.txt cp LICENSE $$WWW/tophide-license.txt echo 'let tophide_version = "$(VERSION)"' > $$WWW/tophide-version.ml tophide-1.0.4/README.md000066400000000000000000000047731275464726300144620ustar00rootroot00000000000000Tophide ======= Tophide is meant to be loaded in an ocaml toplevel. Definitions of values whose name starts with an underscore do not result in the typical 'val NAME : TYPE' output but are simply not shown. This behavior is particularly useful for hiding preprocessor-generated values that are not meant to be reviewed by the user/programmer. Installation ------------ make make install # requires ocamlfind Uninstallation can be performed with make uninstall # requires ocamlfind Usage ----- There are two modes: "hide" and "show". The "hide" mode is automatically triggered when tophide is loaded. It is the mode that hides the values whose name starts with "_". The "show" mode is the regular mode. This mode can be entered using the "#hide" directive. It restores the output functions as they were just before tophide was loaded. The "#hide" directive allows to switch back to the "hide" mode. Example ------- The best way of using this is with findlib. Findlib provides the "#require" directive for finding and loading a given package. ``` #use "topfind";; (* just once *) - : unit = () Findlib has been successfully loaded. Additional directives: #require "package";; to load a package #list;; to list the available packages #camlp4o;; to load camlp4 (standard syntax) #camlp4r;; to load camlp4 (revised syntax) #predicates "p,q,...";; to set these predicates Topfind.reset();; to force that packages will be reloaded #thread;; to enable threads - : unit = () # #require "tophide";; (* loads tophide *) /home/martin/godi/lib/ocaml/site-lib/tophide: added to search path /home/martin/godi/lib/ocaml/site-lib/tophide/tophide.cmo: loaded ``` It is recommended to put these directives into a .ocamlinit file. Then they would be executed at the beginning of each ocaml session. (see chapter "The toplevel system (ocaml)" of the Objective Caml reference manual) Let's see what we get: ```ocaml # let a = 1;; val a : int = 1 # let _a = 2;; (* good, no output for _a! *) # ``` Now you can load your favorite camlp4 extensions. META files ---------- Packages depending on tophide should need it only in the toplevel loop. This is expressed as follows in the `META` file for ocamlfind: requires(toploop) += "tophide" This comes in addition to other `requires` directives, e.g.: requires = "unix pcre" requires(toploop) += "tophide" tophide-1.0.4/tophide.ml000066400000000000000000000050621275464726300151610ustar00rootroot00000000000000(* $Id$ *) (* Copyright 2008 Martin Jambon. All rights reserved. This file is distributed under the terms stated in file LICENSE. *) open Toploop open Outcometree type env = { print_out_class_type : Format.formatter -> out_class_type -> unit; print_out_module_type : Format.formatter -> out_module_type -> unit; print_out_phrase : Format.formatter -> out_phrase -> unit; print_out_sig_item : Format.formatter -> out_sig_item -> unit; print_out_signature : Format.formatter -> out_sig_item list -> unit; print_out_type : Format.formatter -> out_type -> unit; print_out_value : Format.formatter -> out_value -> unit; } let save_env () = { print_out_class_type = !print_out_class_type; print_out_module_type = !print_out_module_type; print_out_phrase = !print_out_phrase; print_out_sig_item = !print_out_sig_item; print_out_signature = !print_out_signature; print_out_type = !print_out_type; print_out_value = !print_out_value; } let load_env env = print_out_class_type := env.print_out_class_type; print_out_module_type := env.print_out_module_type; print_out_phrase := env.print_out_phrase; print_out_sig_item := env.print_out_sig_item; print_out_signature := env.print_out_signature; print_out_type := env.print_out_type; print_out_value := env.print_out_value let default_env = save_env () let filter_sig_item = function Osig_class (_, _, _, _, _) | Osig_class_type (_, _, _, _, _) | Osig_typext _ | Osig_modtype _ | Osig_module _ | Osig_ellipsis | Osig_type _ as x -> Some x | Osig_value {oval_name = name; _} as x -> if name <> "" && name.[0] = '_' then None else Some x let rec select f = function [] -> [] | hd :: tl -> match f hd with None -> select f tl | Some x -> x :: select f tl let special_print_out_phrase fmt x0 = let x = match x0 with Ophr_signature l0 -> let l = select ( fun (si0, ov) -> match filter_sig_item si0 with None -> None | Some si -> Some (si, ov) ) l0 in Ophr_signature l | Ophr_eval _ | Ophr_exception _ -> x0 in default_env.print_out_phrase fmt x let special_env = { default_env with print_out_phrase = special_print_out_phrase } let hide () = load_env special_env let show () = load_env default_env let _ = (* Add "#hide" directive: *) Hashtbl.add directive_table "hide" (Directive_none hide); (* Add "#show" directive: *) Hashtbl.add directive_table "show" (Directive_none show); (* Enter "hide" mode upon loading *) hide ()