* http://helm.cs.unibo.it/
*)
+(** Interpreter for textual phrases coming from matita's console (textual entry
+* window at the bottom of the main window).
+*
+* Interpreter is either in `Command state or in `Proof state (see state_tag type
+* below). In `Command state commands for starting proofs are accepted, but
+* tactic and tactical applications are not. In `Proof state both
+* tactic/tacticals and commands are accepted.
+*)
+
open Printf
type state_tag = [ `Command | `Proof ]
-exception Command_not_found of string
+exception Command_error of string
class virtual interpreterState ~(console: MatitaConsole.console) =
object (self)
method evalPhrase s = self#evalTactical (self#parsePhrase s)
end
+ (** Implements phrases that should be accepted in all states *)
+class sharedState
+ ~(disambiguator: MatitaTypes.disambiguator)
+ ~(proof_handler: MatitaTypes.proof_handler)
+ ~(console: MatitaConsole.console)
+ ()
+=
+ object (self)
+ inherit interpreterState ~console
+ method evalTactical = function
+ | TacticAst.Command TacticAst.Quit ->
+ proof_handler.MatitaTypes.quit ();
+ `Command (* dummy answer, useless *)
+ | TacticAst.Command TacticAst.Proof ->
+ (* do nothing, just for compatibility with coq syntax *)
+ `Command
+ | tactical ->
+ raise (Command_error (TacticAstPp.pp_tactical tactical))
+ end
+
+ (** Implements phrases that should be accepted only in `Command state *)
class commandState
~(disambiguator: MatitaTypes.disambiguator)
~(proof_handler: MatitaTypes.proof_handler)
~(console: MatitaConsole.console)
()
=
+ let shared = new sharedState ~disambiguator ~proof_handler ~console () in
object (self)
inherit interpreterState ~console
method evalTactical = function
-(*
- | TacticAst.Command _ -> failwith "1"
- | TacticAst.Tactic _ -> failwith "2"
- | TacticAst.LocatedTactical _ -> failwith "3"
- | TacticAst.Fail -> failwith "4"
- | TacticAst.Do (_, _) -> failwith "5"
- | TacticAst.IdTac -> failwith "6"
- | TacticAst.Repeat _ -> failwith "7"
- | TacticAst.Seq _ -> failwith "8"
- | TacticAst.Then (_, _) -> failwith "9"
- | TacticAst.Tries _ -> failwith "10"
- | TacticAst.Try _ -> failwith "11"
-*)
| TacticAst.LocatedTactical (_, tactical) -> self#evalTactical tactical
| TacticAst.Command (TacticAst.Theorem (_, Some name, ast, None)) ->
let (_, metasenv, expr) = disambiguator#disambiguateTermAst ast in
- let _ = CicTypeChecker.type_of_aux' metasenv [] expr in
let proof = MatitaProof.proof ~typ:expr ~metasenv () in
proof_handler.MatitaTypes.new_proof proof;
`Proof
| TacticAst.Command TacticAst.Proof ->
(* do nothing, just for compatibility with coq syntax *)
`Command
- | tactical ->
- raise (Command_not_found (TacticAstPp.pp_tactical tactical))
+ | tactical -> shared#evalTactical tactical
end
+let rec lookup_tactic = function
+ | TacticAst.LocatedTactic (_, tactic) -> lookup_tactic tactic
+ | TacticAst.Intros (_, names) ->
+ let namer =
+ (** use names given by the user as long as they are availble, then
+ * fallback on default fresh name generator *)
+ let len = List.length names in
+ let count = ref 0 in
+ fun metasenv context name ~typ ->
+ if !count < len then begin
+ let name = Cic.Name (List.nth names !count) in
+ incr count;
+ name
+ end else
+ FreshNamesGenerator.mk_fresh_name metasenv context name ~typ
+ in
+ PrimitiveTactics.intros_tac ~mk_fresh_name_callback:namer ()
+ | TacticAst.Reflexivity -> EqualityTactics.reflexivity_tac
+ | TacticAst.Assumption -> VariousTactics.assumption_tac
+ | TacticAst.Contradiction -> NegationTactics.contradiction_tac
+ | TacticAst.Exists -> IntroductionTactics.exists_tac
+ | TacticAst.Fourier -> FourierR.fourier_tac
+ | TacticAst.Left -> IntroductionTactics.left_tac
+ | TacticAst.Right -> IntroductionTactics.right_tac
+ | TacticAst.Ring -> Ring.ring_tac
+ | TacticAst.Split -> IntroductionTactics.split_tac
+ | TacticAst.Symmetry -> EqualityTactics.symmetry_tac
+(*
+ (* TODO Zack a lot more of tactics to be implemented here ... *)
+ | TacticAst.Absurd
+ | TacticAst.Apply of 'term
+ | TacticAst.Change of 'term * 'term * 'ident option
+ | TacticAst.Change_pattern of 'term pattern * 'term * 'ident option
+ | TacticAst.Cut of 'term
+ | TacticAst.Decompose of 'ident * 'ident list
+ | TacticAst.Discriminate of 'ident
+ | TacticAst.Elim of 'term * 'term option
+ | TacticAst.ElimType of 'term
+ | TacticAst.Exact of 'term
+ | TacticAst.Fold of reduction_kind * 'term
+ | TacticAst.Injection of 'ident
+ | TacticAst.Intros of int option * 'ident list
+ | TacticAst.LetIn of 'term * 'ident
+ | TacticAst.Reduce of reduction_kind * 'term pattern * 'ident option
+ | TacticAst.Replace of 'term * 'term
+ | TacticAst.Replace_pattern of 'term pattern * 'term
+ | TacticAst.Rewrite of direction * 'term * 'ident option
+ | TacticAst.Transitivity of 'term
+*)
+ | _ ->
+ MatitaTypes.not_implemented "some tactic"
+
+ (** Implements phrases that should be accepted only in `Proof state, basically
+ * tacticals *)
class proofState
~(disambiguator: MatitaTypes.disambiguator)
~(proof_handler: MatitaTypes.proof_handler)
~(console: MatitaConsole.console)
()
=
- let commandState =
- new commandState ~disambiguator ~proof_handler ~console ()
- in
- object
+ let shared = new sharedState ~disambiguator ~proof_handler ~console () in
+ object (self)
inherit interpreterState ~console
method evalTactical = function
+ | TacticAst.LocatedTactical (_, tactical) -> self#evalTactical tactical
| TacticAst.Command TacticAst.Abort ->
proof_handler.MatitaTypes.set_proof None;
`Command
- | tactical -> (* fallback on command state *)
- commandState#evalTactical tactical
+ | TacticAst.Seq tacticals ->
+ (* TODO Zack check for proof completed at each step? *)
+ List.iter (fun t -> ignore (self#evalTactical t)) tacticals;
+ `Proof
+ | TacticAst.Tactic tactic_phrase ->
+ let tactic = lookup_tactic tactic_phrase in
+ (proof_handler.MatitaTypes.get_proof ())#apply_tactic tactic;
+ `Proof
+ | tactical -> shared#evalTactical tactical
end
class interpreter