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
let comment str =
if Pcre.pmatch ~rex:multiline_RE str then
- "\n(** " ^ (Pcre.replace ~rex:newline_RE str) ^ " **)"
+ "\n(** " ^ (Pcre.replace ~rex:newline_RE str) ^ " *)"
else
- "\n(**\n" ^ str ^ "\n**)"
+ "\n(**\n" ^ str ^ "\n*)"
let first_line s =
let s = Pcre.replace ~rex:heading_nl_RE s in
let new_aliases =
match ex with
| TA.Command (_, TA.Alias _)
- | TA.Command (_, TA.Include _) -> DisambiguateTypes.Environment.empty
+ | TA.Command (_, TA.Include _)
+ | TA.Command (_, TA.Interpretation _) ->
+ DisambiguateTypes.Environment.empty
| _ -> MatitaSync.alias_diff ~from:status new_status
in
(* we remove the defined object since we consider them "automatic aliases" *)
let initial_space,status,new_status_and_text_list_rev =
let module DTE = DisambiguateTypes.Environment in
let module UM = UriManager in
- DTE.fold (
+ DTE.fold_flatten (
fun k ((v,_) as value) (initial_space,status,acc) ->
let b =
try
let initial_space =
if initial_space = "" then "\n" else initial_space in
initial_space ^
- DisambiguatePp.pp_environment(DTE.add k value DTE.empty) in
+ DisambiguatePp.pp_environment(DTE.cons k value DTE.empty) in
let new_status =
- {status with aliases = DTE.add k value status.aliases}
+ {status with aliases = DTE.cons k value status.aliases}
in
"\n",new_status,((new_status, new_text)::acc)
) new_aliases (initial_space,status,[]) in
let aliases = MatitaMisc.get_proof_aliases status in
let interps = MD.disambiguate_term dbd context metasenv aliases term in
match interps with
- | [_,_,x,_] -> x
+ | [_,_,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) ->
in
let _, metasenv , term, ugraph =
match interps with
- | [x] -> x
+ | [x], _ -> x
| _ -> assert false
in
let ty,_ = CTC.type_of_aux' metasenv context term ugraph in
| 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