From: Stefano Zacchiroli Date: Tue, 6 Sep 2005 14:37:42 +0000 (+0000) Subject: misc fixes in cic browser queries (pretty printing, url bar, ...) X-Git-Tag: V_0_1_2_1~74 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=639131d311fd0f111e09feca7b567b28d21e873f;p=helm.git misc fixes in cic browser queries (pretty printing, url bar, ...) --- diff --git a/helm/matita/matitaMathView.ml b/helm/matita/matitaMathView.ml index de08f538e..b1970857f 100644 --- a/helm/matita/matitaMathView.ml +++ b/helm/matita/matitaMathView.ml @@ -28,17 +28,6 @@ open Printf open MatitaTypes open MatitaGtkMisc -let add_trailing_slash = - let rex = Pcre.regexp "/$" in - fun s -> - if Pcre.pmatch ~rex s then s - else s ^ "/" - -let strip_blanks = - let rex = Pcre.regexp "^\\s*([^\\s]*)\\s*$" in - fun s -> - (Pcre.extract ~rex s).(1) - (** inherit from this class if you want to access current script *) class scriptAccessor = object (self) @@ -780,7 +769,7 @@ class cicBrowser_impl ~(history:MatitaTypes.mathViewer_entry MatitaMisc.history) (** this is what the browser does when you enter a string an hit enter *) method loadInput txt = - let txt = strip_blanks txt in + let txt = MatitaMisc.trim_blanks txt in let fix_uri txt = UriManager.string_of_uri (UriManager.strip_xpointer (UriManager.uri_of_string txt)) @@ -792,7 +781,7 @@ class cicBrowser_impl ~(history:MatitaTypes.mathViewer_entry MatitaMisc.history) let entry = match txt with | txt when is_uri txt -> `Uri (UriManager.uri_of_string (fix_uri txt)) - | txt when is_dir txt -> `Dir (add_trailing_slash txt) + | txt when is_dir txt -> `Dir (MatitaMisc.normalize_dir txt) | txt -> (try entry_of_string txt diff --git a/helm/matita/matitaMisc.ml b/helm/matita/matitaMisc.ml index e3aadd5b5..78e780a15 100644 --- a/helm/matita/matitaMisc.ml +++ b/helm/matita/matitaMisc.ml @@ -26,9 +26,11 @@ open Printf open MatitaTypes -let strip_trailing_slash = - let rex = Pcre.regexp "/$" in - fun s -> Pcre.replace ~rex s +(** Functions "imported" from Http_getter_misc *) + +let strip_trailing_slash = Http_getter_misc.strip_trailing_slash +let normalize_dir = Http_getter_misc.normalize_dir +let strip_suffix = Http_getter_misc.strip_suffix let baseuri_of_baseuri_decl st = match st with @@ -129,9 +131,9 @@ let mkdir path = in aux "" components -let strip_trailing_blanks = - let rex = Pcre.regexp "\\s*$" in - fun s -> Pcre.replace ~rex s +let trim_blanks = + let rex = Pcre.regexp "^\\s*(.*?)\\s*$" in + fun s -> (Pcre.extract ~rex s).(1) let split ?(char = ' ') s = let pieces = ref [] in diff --git a/helm/matita/matitaMisc.mli b/helm/matita/matitaMisc.mli index c4adbf6e1..9cbada588 100644 --- a/helm/matita/matitaMisc.mli +++ b/helm/matita/matitaMisc.mli @@ -51,8 +51,10 @@ val is_proof_object: string -> bool * it *) val append_phrase_sep: string -> string -val strip_trailing_blanks: string -> string +val trim_blanks: string -> string val strip_trailing_slash: string -> string +val normalize_dir: string -> string (** add trailing "/" if missing *) +val strip_suffix: suffix:string -> string -> string (* split a string at character, char defaults to ' ' *) val split: ?char:char -> string -> string list diff --git a/helm/matita/matitaScript.ml b/helm/matita/matitaScript.ml index 6e074787c..987e60560 100644 --- a/helm/matita/matitaScript.ml +++ b/helm/matita/matitaScript.ml @@ -26,8 +26,8 @@ open Printf open MatitaTypes -let debug = true -let debug_print = if debug then prerr_endline else ignore +let debug = false +let debug_print = if debug then prerr_endline else ignore (** raised when one of the script margins (top or bottom) is reached *) exception Margin @@ -210,8 +210,7 @@ let disambiguate term status = | [_,_,x,_] -> x | _ -> assert false -let eval_macro guistuff status parsed_text script mac -= +let eval_macro guistuff status unparsed_text parsed_text script mac = let module TA = GrafiteAst in let module TAPp = GrafiteAstPp in let module MQ = MetadataQuery in @@ -227,7 +226,11 @@ let eval_macro guistuff status parsed_text script mac | TA.WMatch (loc, term) -> let term = disambiguate term status in let l = MQ.match_term ~dbd term in - let entry = `Whelp (TAPp.pp_macro_cic (TA.WMatch (loc, term)), l) in + let query_url = + MatitaMisc.strip_suffix ~suffix:"." + (MatitaMisc.trim_blanks unparsed_text) + in + let entry = `Whelp (query_url, l) in guistuff.mathviewer#show_uri_list ~reuse:true ~entry l; [], parsed_text_length | TA.WInstance (loc, term) -> @@ -326,7 +329,9 @@ let eval_macro guistuff status parsed_text script mac | TA.Search_term (_, search_kind, term) -> failwith "not implemented" -let eval_executable guistuff status user_goal parsed_text script ex = +let eval_executable guistuff status user_goal unparsed_text parsed_text script + ex += let module TA = GrafiteAst in let module TAPp = GrafiteAstPp in let module MD = MatitaDisambiguator in @@ -354,15 +359,15 @@ let eval_executable guistuff status user_goal parsed_text script ex = guistuff status user_goal parsed_text (TA.Executable (loc, ex)) with MatitaTypes.Cancel -> [], 0) | TA.Macro (_,mac) -> - eval_macro guistuff status parsed_text script mac + eval_macro guistuff status unparsed_text parsed_text script mac let rec eval_statement baseoffset parsedlen error_tag (buffer : GText.buffer) - guistuff status user_goal script s + guistuff status user_goal script unparsed_text = - if Pcre.pmatch ~rex:only_dust_RE s then raise Margin; + if Pcre.pmatch ~rex:only_dust_RE unparsed_text then raise Margin; let st = try - GrafiteParser.parse_statement (Stream.of_string s) + GrafiteParser.parse_statement (Stream.of_string unparsed_text) with CicNotationParser.Parse_error (floc,err) as exc -> let (x, y) = CicNotationPt.loc_of_floc floc in @@ -392,14 +397,14 @@ let rec eval_statement baseoffset parsedlen error_tag (buffer : GText.buffer) in let text_of_loc loc = let parsed_text_length = snd (CicNotationPt.loc_of_floc loc) in - let parsed_text = safe_substring s 0 parsed_text_length in + let parsed_text = safe_substring unparsed_text 0 parsed_text_length in parsed_text, parsed_text_length in match st with - | GrafiteAst.Comment (loc,_)-> + | GrafiteAst.Comment (loc, _) -> let parsed_text, parsed_text_length = text_of_loc loc in - let remain_len = String.length s - parsed_text_length in - let s = String.sub s parsed_text_length remain_len in + let remain_len = String.length unparsed_text - parsed_text_length in + let s = String.sub unparsed_text parsed_text_length remain_len in let s,len = eval_statement baseoffset (parsedlen + parsed_text_length) error_tag buffer guistuff status user_goal script s @@ -410,7 +415,8 @@ let rec eval_statement baseoffset parsedlen error_tag (buffer : GText.buffer) | [] -> [], 0) | GrafiteAst.Executable (loc, ex) -> let parsed_text, parsed_text_length = text_of_loc loc in - eval_executable guistuff status user_goal parsed_text script ex + eval_executable guistuff status user_goal unparsed_text parsed_text + script ex let fresh_script_id = let i = ref 0 in diff --git a/helm/matita/matitacLib.ml b/helm/matita/matitacLib.ml index 0eb297776..e7d3f18e6 100644 --- a/helm/matita/matitacLib.ml +++ b/helm/matita/matitacLib.ml @@ -88,7 +88,7 @@ let fname () = Arg.parse arg_spec add_script usage; match !acc with | [x] -> x - | _ -> prerr_endline usage; exit 1 + | _ -> print_endline usage; exit 1 let pp_ocaml_mode () = MatitaLog.message ""; diff --git a/helm/matita/matitaclean.ml b/helm/matita/matitaclean.ml index c7bbdf453..f42973f90 100644 --- a/helm/matita/matitaclean.ml +++ b/helm/matita/matitaclean.ml @@ -36,13 +36,13 @@ let _ = let main uri_to_remove = MatitacleanLib.clean_baseuris uri_to_remove let usage () = - prerr_endline ""; - prerr_endline "usage:"; - prerr_endline "\tmatitaclean all"; - prerr_endline "\t\tcleans the whole environment"; - prerr_endline "\tmatitaclean files..."; - prerr_endline "\t\tcleans the output of the compilation of files...\n"; - prerr_endline ""; + prerr_endline " +usage: +\tmatitaclean all +\t\tcleans the whole environment +\tmatitaclean files... +\t\tcleans the output of the compilation of files... +"; exit 1 let _ =