]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/test/editor.cc
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / test / editor.cc
index b251d4ede2ff8fe4988e0d37ef318375c90e592f..3efc17cee2168b72acb5429a1f73c3c9bdb12c78 100644 (file)
@@ -1,8 +1,35 @@
+/* This file is part of EdiTeX, an editor of mathematical
+ * expressions based on TeX syntax.
+ * 
+ * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
+ *                    2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * For more information, please visit the project's home page
+ * http://helm.cs.unibo.it/editex/
+ * or send an email to <lpadovan@cs.unibo.it>
+ */
+
+#include <cassert>
 
 #include "dom.hh"
 #include "TPushParser.hh"
-#include "TPushLexer.hh"
-#include "LPushLexer.hh"
+#include "timer.hh"
+
+#include "ILPushLexer.hh"
 #include "TDictionary.hh"
 #include "CLoggerConsole.hh"
 #include "CMathMLFactoryXSLT.hh"
@@ -15,6 +42,9 @@ extern void *parseMathMLFile(char *);
 
 struct Context
 {
+  /*
+  Context(const std::string& s, TPushLexer& l, TPushParser& p) : buffer(s), i(0), lexer(l), parser(p) { };
+  */
   Context(const std::string& s, APushLexer& l, TPushParser& p, DOMX::XSLTStylesheet& ts) 
     : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { };
 
@@ -38,9 +68,9 @@ edit_output_tex(Context* data)
 #if 0
   res.normalize();
   DOM::Node c = res.get_firstChild();
-  if (c) cout << "HEY, there is a child! " << c.get_nodeName() << " " << c.get_nodeValue() << endl;
+  if (c) std::cout << "HEY, there is a child! " << c.get_nodeName() << " " << c.get_nodeValue() << std::endl;
 #endif
-  data->texStyle.save(res, stdout);
+  //data->texStyle.save(res, stdout);
 }
 
 extern "C" int
@@ -57,10 +87,13 @@ extern "C" void
 edit_push_char(Context* context, gchar ch)
 {
   assert(context != NULL);
+  long t0 = getTimer();
   GUI_freeze();
-  cout << "*** SENDING " << ch << endl;
+  std::cout << "*** SENDING " << ch << std::endl;
   context->lexer.push(ch);
   GUI_thaw();
+  long t1 = getTimer();
+  std::cout << "=== OVERALL TIME = " << (t1 - t0) / 1000 << std::endl;
 }
 
 #include <unistd.h>
@@ -88,8 +121,10 @@ edit_push_string(Context* context, const gchar* s)
 }
 
 extern "C" void
-edit_drop(Context* context, gboolean alt)
+edit_drop(Context* context, gboolean alt, gboolean control)
 {
+  // At the moment, the last parameter is not used, but it will
+  // be useful when we will handle the "fast" deletion
   assert(context != NULL);
   GUI_freeze();
   context->lexer.drop(alt);
@@ -106,7 +141,16 @@ edit_reset_tex(Context* context)
   GUI_thaw();
 }
 
-void
+extern "C" void
+edit_complete(Context* context)
+{
+  assert(context != NULL);
+  GUI_freeze();
+  if (!context->lexer.complete()) context->lexer.push('\t');
+  GUI_thaw();
+}
+
+int
 main(int argc, char* argv[])
 {
   CLoggerConsole logger;
@@ -114,19 +158,19 @@ main(int argc, char* argv[])
 
   TDictionary dictionary(logger);
   logger.info("loading the dictionary...");
-  dictionary.load("/home/luca/projects/helm/DEVEL/mathml_editor/dictionary-test.xml");
+  dictionary.load("./dict/dictionary-tex.xml");
 
   logger.info("loading the stylesheet...");
   DOM::DOMImplementation di;
   DOM::Document mmlStyleDoc = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
   DOMX::XSLTStylesheet mmlStyle(mmlStyleDoc);
 
-  DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-tex.xsl");
+  DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-texid.xsl");
   DOMX::XSLTStylesheet texStyle(texStyleDoc);
 
   CMathMLFactoryXSLT factory(logger, mmlStyle);
   TPushParser parser(logger, factory, dictionary);
-  LPushLexer lexer(logger, parser);
+  ILPushLexer lexer(logger, parser, dictionary);
 
 #if 0
   lexer.push('$');
@@ -143,9 +187,10 @@ main(int argc, char* argv[])
 
   Context context("", lexer, parser, texStyle);
 
-  GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
+  GUI_init(&argc, &argv, "EditTeX", 500, 600, &context);
   GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(factory.document())));
   GUI_run();
   GUI_uninit();
   GUI_unload_document();
+
 }