in
Arg.parse argspec ignore ""
+(* A WIDGET TO ENTER CIC TERMS *)
+
+class term_editor ?packing ?width ?height () =
+ let input = GEdit.text ~editable:true ?width ?height ?packing () in
+object(self)
+ method coerce = input#coerce
+ method reset =
+ input#delete_text 0 input#length
+ method set_term txt =
+ self#reset ;
+ ignore ((input#insert_text txt) ~pos:0)
+ method get_term ~context ~metasenv =
+ let lexbuf = Lexing.from_string (input#get_chars 0 input#length) in
+ CicTextualParserContext.main ~context ~metasenv CicTextualLexer.token lexbuf
+end
+;;
(* MISC FUNCTIONS *)
;;
let locate () =
- let inputt = ((rendering_window ())#inputt : GEdit.text) in
+ let inputt = ((rendering_window ())#inputt : term_editor) in
let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
try
match
None -> raise NoChoice
| Some input ->
let uri = locate_callback input in
- inputt#delete_text 0 inputt#length ;
- ignore ((inputt#insert_text uri) ~pos:0)
+ inputt#set_term uri
with
e ->
output_html outputhtml
;;
let state () =
- let inputt = ((rendering_window ())#inputt : GEdit.text) in
+ let inputt = ((rendering_window ())#inputt : term_editor) in
let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
let output = ((rendering_window ())#output : GMathView.math_view) in
let notebook = (rendering_window ())#notebook in
- let inputlen = inputt#length in
- let input = inputt#get_chars 0 inputlen ^ "\n" in
- (* Do something interesting *)
- let lexbuf = Lexing.from_string input in
- try
- let dom,mk_metasenv_and_expr =
- CicTextualParserContext.main [] [] CicTextualLexer.token lexbuf
- in
- let metasenv,expr =
- disambiguate_input [] [] dom mk_metasenv_and_expr
- in
- let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
- ProofEngine.proof :=
- Some (UriManager.uri_of_string "cic:/dummy.con",
- (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
- ProofEngine.goal := Some 1 ;
- refresh_sequent notebook ;
- refresh_proof output ;
- !save_set_sensitive true ;
- inputt#delete_text 0 inputlen
- with
- RefreshSequentException e ->
- output_html outputhtml
- ("<h1 color=\"red\">Exception raised during the refresh of the " ^
- "sequent: " ^ Printexc.to_string e ^ "</h1>")
- | RefreshProofException e ->
- output_html outputhtml
- ("<h1 color=\"red\">Exception raised during the refresh of the " ^
- "proof: " ^ Printexc.to_string e ^ "</h1>")
- | e ->
- output_html outputhtml
- ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
+ try
+ let dom,mk_metasenv_and_expr = inputt#get_term [] [] in
+ let metasenv,expr =
+ disambiguate_input [] [] dom mk_metasenv_and_expr
+ in
+ let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
+ ProofEngine.proof :=
+ Some
+ (UriManager.uri_of_string "cic:/dummy.con",
+ (1,[],expr)::metasenv, Cic.Meta (1,[]), expr) ;
+ ProofEngine.goal := Some 1 ;
+ refresh_sequent notebook ;
+ refresh_proof output ;
+ !save_set_sensitive true ;
+ inputt#reset
+ with
+ RefreshSequentException e ->
+ output_html outputhtml
+ ("<h1 color=\"red\">Exception raised during the refresh of the " ^
+ "sequent: " ^ Printexc.to_string e ^ "</h1>")
+ | RefreshProofException e ->
+ output_html outputhtml
+ ("<h1 color=\"red\">Exception raised during the refresh of the " ^
+ "proof: " ^ Printexc.to_string e ^ "</h1>")
+ | e ->
+ output_html outputhtml
+ ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
;;
let check_term_in_scratch scratch_window metasenv context expr =
;;
let check scratch_window () =
- let inputt = ((rendering_window ())#inputt : GEdit.text) in
+ let inputt = ((rendering_window ())#inputt : term_editor) in
let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
- let inputlen = inputt#length in
- let input = inputt#get_chars 0 inputlen ^ "\n" in
- let curi,metasenv =
+ let metasenv =
match !ProofEngine.proof with
- None -> UriManager.uri_of_string "cic:/dummy.con", []
- | Some (curi,metasenv,_,_) -> curi,metasenv
+ None -> []
+ | Some (_,metasenv,_,_) -> metasenv
in
let context,names_context =
let context =
| None -> None
) context
in
- let lexbuf = Lexing.from_string input in
- try
- let dom,mk_metasenv_and_expr =
- CicTextualParserContext.main names_context metasenv CicTextualLexer.token
- lexbuf
+ try
+ let dom,mk_metasenv_and_expr = inputt#get_term names_context metasenv in
+ let (metasenv',expr) =
+ disambiguate_input context metasenv dom mk_metasenv_and_expr
in
- let (metasenv',expr) =
- disambiguate_input context metasenv dom mk_metasenv_and_expr
- in
- check_term_in_scratch scratch_window metasenv' context expr
- with
- e ->
- output_html outputhtml
- ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
+ check_term_in_scratch scratch_window metasenv' context expr
+ with
+ e ->
+ output_html outputhtml
+ ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
;;
let notebook = (rendering_window ())#notebook in
let output = ((rendering_window ())#output : GMathView.math_view) in
let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
- let inputt = ((rendering_window ())#inputt : GEdit.text) in
+ let inputt = ((rendering_window ())#inputt : term_editor) in
let savedproof = !ProofEngine.proof in
let savedgoal = !ProofEngine.goal in
-(*CSC: Gran cut&paste da sotto... *)
- let inputlen = inputt#length in
- let input = inputt#get_chars 0 inputlen ^ "\n" in
- let lexbuf = Lexing.from_string input in
- let curi =
- match !ProofEngine.proof with
- None -> assert false
- | Some (curi,_,_,_) -> curi
- in
- let uri,metasenv,bo,ty =
- match !ProofEngine.proof with
- None -> assert false
- | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
- in
+ let uri,metasenv,bo,ty =
+ match !ProofEngine.proof with
+ None -> assert false
+ | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
+ in
let canonical_context =
match !ProofEngine.goal with
None -> assert false
) canonical_context
in
try
- let dom,mk_metasenv_and_expr =
- CicTextualParserContext.main context metasenv CicTextualLexer.token lexbuf
- in
+ let dom,mk_metasenv_and_expr = inputt#get_term context metasenv in
let (metasenv',expr) =
disambiguate_input canonical_context metasenv dom mk_metasenv_and_expr
in
tactic expr ;
refresh_sequent notebook ;
refresh_proof output ;
- inputt#delete_text 0 inputlen
+ inputt#reset
with
RefreshSequentException e ->
output_html outputhtml
let notebook = (rendering_window ())#notebook in
let output = ((rendering_window ())#output : GMathView.math_view) in
let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
- let inputt = ((rendering_window ())#inputt : GEdit.text) in
+ let inputt = ((rendering_window ())#inputt : term_editor) in
let savedproof = !ProofEngine.proof in
let savedgoal = !ProofEngine.goal in
match notebook#proofw#get_selection with
match !current_goal_infos with
Some (ids_to_terms, ids_to_father_ids,_) ->
let id = xpath in
- (* Let's parse the input *)
- let inputlen = inputt#length in
- let input = inputt#get_chars 0 inputlen ^ "\n" in
- let lexbuf = Lexing.from_string input in
- let curi =
- match !ProofEngine.proof with
- None -> assert false
- | Some (curi,_,_,_) -> curi
- in
- let uri,metasenv,bo,ty =
- match !ProofEngine.proof with
- None -> assert false
- | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
- in
+ let uri,metasenv,bo,ty =
+ match !ProofEngine.proof with
+ None -> assert false
+ | Some (uri,metasenv,bo,ty) -> uri,metasenv,bo,ty
+ in
let canonical_context =
match !ProofEngine.goal with
None -> assert false
| None -> None
) canonical_context
in
- let dom,mk_metasenv_and_expr =
- CicTextualParserContext.main context metasenv
- CicTextualLexer.token lexbuf
+ let dom,mk_metasenv_and_expr = inputt#get_term context metasenv
in
let (metasenv',expr) =
disambiguate_input canonical_context metasenv dom
~input:expr ;
refresh_sequent notebook ;
refresh_proof output ;
- inputt#delete_text 0 inputlen
+ inputt#reset
| None -> assert false (* "ERROR: No current term!!!" *)
with
RefreshSequentException e ->
let searchPattern () =
- let inputt = ((rendering_window ())#inputt : GEdit.text) in
+ let inputt = ((rendering_window ())#inputt : term_editor) in
let outputhtml = ((rendering_window ())#outputhtml : GHtml.xmhtml) in
try
let rec get_level ?(last_invalid=false) () =
"Many lemmas can be successfully applied. Please, choose one:"
uris'
in
- inputt#delete_text 0 inputt#length ;
- ignore ((inputt#insert_text uri') ~pos:0) ;
+ inputt#set_term uri' ;
apply ()
with
e ->
let scrolled_window1 =
GBin.scrolled_window ~border_width:5
~packing:(vbox'#pack ~expand:true ~padding:0) () in
- let inputt = GEdit.text ~editable:true ~width:400 ~height:100
- ~packing:scrolled_window1#add () in
+ let inputt =
+ new term_editor ~width:400 ~height:100 ~packing:scrolled_window1#add () in
let vboxl =
GPack.vbox ~packing:(hbox0#pack ~expand:true ~fill:true ~padding:5) () in
let _ =