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)
(** 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))
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
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
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
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
| [_,_,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
| 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) ->
| 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
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
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
| [] -> [], 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