(* 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) ~(proof_handler: MatitaTypes.proof_handler) ~(console: MatitaConsole.console) () = 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 proof_handler.MatitaTypes.new_proof proof; `Proof | CommandAst.Quit _ -> proof_handler.MatitaTypes.quit (); `Command (* dummy answer *) | _ -> MatitaTypes.not_implemented (* TODO Zack *) "MatitaInterpreter.commandState#evalPhrase: commands other than full theorem ones"; `Proof end (* TODO Zack FINQUI * bisogna rivedere la grammatica di tatticali/comandi * molti comandi (o addirittura tutti tranne Theorem) hanno senso anche nello * stato proof, e' quindi un casino parsare la phrase. Un'idea potrebbe essere * quella di tentare di parsare una tattica e se il parsing fallisce provare a * parsare un comando (BLEAARGH). Oppure si puo' aggiungere una possibile entry * nella grammatica delle tattiche che punti ad un comando (RI-BLEAARGH). * Oppure boh ... *) class proofState ~(disambiguator: MatitaTypes.disambiguator) ~(proof_handler: MatitaTypes.proof_handler) ~(console: MatitaConsole.console) () = object method evalPhrase (s: string): state_tag = (* TODO Zack *) MatitaTypes.not_implemented "MatitaInterpreter.proofState#evalPhrase"; `Command end class interpreter ~(disambiguator: MatitaTypes.disambiguator) ~(proof_handler: MatitaTypes.proof_handler) ~(console: MatitaConsole.console) () = let commandState = lazy (new commandState ~disambiguator ~proof_handler ~console ()) in let proofState = lazy (new proofState ~disambiguator ~proof_handler ~console ()) 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