+(* Copyright (C) 2004, HELM Team.
+ *
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ *
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ *
+ * For details, see the HELM World-Wide-Web page,
+ * http://helm.cs.unibo.it/
+ *)
+
+type state_tag = [ `Command | `Proof ]
+
+class type interpreterState =
+ object
+ (** eval a toplevel phrase in the current state and return the new state
+ *)
+ method evalPhrase: string -> state_tag
+ end
+
+class commandState
+ ~(disambiguator: MatitaTypes.disambiguator)
+ ~(console: MatitaConsole.console)
+ ~new_proof ()
+=
+ object
+ method evalPhrase s: state_tag =
+ let command = CicTextualParser2.parse_command (Stream.of_string s) in
+ match command with
+ | CommandAst.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
+ new_proof proof;
+ `Proof
+ | _ ->
+ MatitaTypes.not_implemented (* TODO Zack *)
+ "MatitaInterpreter.commandState#evalPhrase: commands other than full theorem ones";
+ `Proof
+ end
+
+class proofState
+ ~(disambiguator: MatitaTypes.disambiguator)
+ ~(console: MatitaConsole.console)
+ ~get_proof ()
+=
+ object
+ method evalPhrase (s: string): state_tag =
+ (* TODO Zack *)
+ MatitaTypes.not_implemented "MatitaInterpreter.proofState#evalPhrase";
+ `Command
+ end
+
+class interpreter
+ ~(disambiguator: MatitaTypes.disambiguator)
+ ~(console: MatitaConsole.console)
+ ~(get_proof: unit -> MatitaTypes.proof)
+ ~(new_proof: MatitaTypes.proof -> unit)
+ ()
+=
+ let commandState =
+ lazy (new commandState ~disambiguator ~console ~new_proof ())
+ in
+ let proofState =
+ lazy (new proofState ~disambiguator ~console ~get_proof ())
+ in
+ object
+ val mutable state = Lazy.force commandState
+
+ method evalPhrase s =
+ match state#evalPhrase s with
+ | `Command -> state <- Lazy.force commandState
+ | `Proof -> state <- Lazy.force proofState
+ end
+