]> matita.cs.unibo.it Git - helm.git/commitdiff
* code cleanup
authorLuca Padovani <luca.padovani@unito.it>
Fri, 31 Jan 2003 09:13:55 +0000 (09:13 +0000)
committerLuca Padovani <luca.padovani@unito.it>
Fri, 31 Jan 2003 09:13:55 +0000 (09:13 +0000)
* added logger class and a simple implementation on console
* moved transformation code from test into a mathml factory class
* added .cvsignore files

30 files changed:
helm/DEVEL/mathml_editor/.cvsignore [new file with mode: 0644]
helm/DEVEL/mathml_editor/LICENSE
helm/DEVEL/mathml_editor/src/.cvsignore [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/ALogger.hh [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/AMathMLFactory.hh [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/APushLexer.hh
helm/DEVEL/mathml_editor/src/APushParser.hh
helm/DEVEL/mathml_editor/src/CLoggerConsole.cc [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/CLoggerConsole.hh [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh [new file with mode: 0644]
helm/DEVEL/mathml_editor/src/Makefile.am
helm/DEVEL/mathml_editor/src/Makefile.in
helm/DEVEL/mathml_editor/src/TDictionary.cc
helm/DEVEL/mathml_editor/src/TDocument.cc
helm/DEVEL/mathml_editor/src/TPushLexer.cc
helm/DEVEL/mathml_editor/src/TPushLexer.hh
helm/DEVEL/mathml_editor/src/TPushParser.cc
helm/DEVEL/mathml_editor/src/TPushParser.hh
helm/DEVEL/mathml_editor/src/TTokenizer.cc
helm/DEVEL/mathml_editor/src/TTokenizer.hh
helm/DEVEL/mathml_editor/src/dom.hh
helm/DEVEL/mathml_editor/test/.cvsignore [new file with mode: 0644]
helm/DEVEL/mathml_editor/test/Makefile.am
helm/DEVEL/mathml_editor/test/Makefile.in
helm/DEVEL/mathml_editor/test/editor.cc
helm/DEVEL/mathml_editor/test/guiGTK.c
helm/DEVEL/mathml_editor/test/main.cc [deleted file]
helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl

diff --git a/helm/DEVEL/mathml_editor/.cvsignore b/helm/DEVEL/mathml_editor/.cvsignore
new file mode 100644 (file)
index 0000000..42bb76f
--- /dev/null
@@ -0,0 +1,15 @@
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache
+config.h
+config.h.in
+config.log
+config.status
+configure
+editex-config
+libtool
+result.xml
+stamp-h
+stamp-h.in
+t1lib.log
index f67b1308a1e189022a4b85e2d50075a3d97da8d6..122827fd6d818566f752aba1a1685fd4e381d763 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2002, Luca Padovani <luca.padovani@cs.unibo.it>.
+// Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>.
 //
 // This file is part of EdiTeX, an editor of mathematical
 // expressions based on TeX syntax
diff --git a/helm/DEVEL/mathml_editor/src/.cvsignore b/helm/DEVEL/mathml_editor/src/.cvsignore
new file mode 100644 (file)
index 0000000..87f480e
--- /dev/null
@@ -0,0 +1,8 @@
+*~
+*.lo
+*.o
+*.la
+.deps
+.libs
+Makefile
+Makefile.in
diff --git a/helm/DEVEL/mathml_editor/src/ALogger.hh b/helm/DEVEL/mathml_editor/src/ALogger.hh
new file mode 100644 (file)
index 0000000..d3636f5
--- /dev/null
@@ -0,0 +1,29 @@
+
+#ifndef __ALogger_hh__
+#define __ALogger_hh__
+
+#include <string>
+
+class ALogger
+{
+public:
+  enum Level { Error, Warning, Info, Debug };
+
+  ALogger(void) { level = Error; }
+  virtual ~ALogger() { }
+  void debug(const std::string& msg) { if (level >= Debug) message(Debug, msg); }
+  void info(const std::string& msg) { if (level >= Info) message(Info, msg); }
+  void warning(const std::string& msg) { if (level >= Warning) message(Warning, msg); }
+  void error(const std::string& msg) { if (level >= Error) message(Error, msg); }
+
+  Level verbosity(void) const { return level; }
+  void  verbosity(Level lvl) { level = lvl; }
+
+protected:
+  virtual void message(Level, const std::string&) = 0;
+
+private:
+  Level level;
+};
+
+#endif // __ALogger_hh__
diff --git a/helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh b/helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh
new file mode 100644 (file)
index 0000000..76b6417
--- /dev/null
@@ -0,0 +1,14 @@
+
+
+#ifndef __AMathMLConsumer_hh__
+#define __AMathMLConsumer_hh__
+
+class AMathMLConsumer
+{
+public:
+  AMathMLConsumer(void) { };
+  virtual ~AMathMLConsumer() { };
+  virtual void documentModified(const DOM::Document&) = 0;
+};
+
+#endif // __AMathMLConsumer_hh__
diff --git a/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh b/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh
new file mode 100644 (file)
index 0000000..a514e94
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>.
+//
+// This file is part of EdiTeX, an editor of mathematical
+// expressions based on TeX syntax
+// 
+// EdiTeX 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.
+//
+// EdiTeX 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 EdiTeX; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// 
+// For details, see the EdiTeX World-Wide-Web page,
+// http://helm.cs.unibo.it/editex, or send a mail to
+// <luca.padovani@cs.unibo.it>
+
+#ifndef __AMathMLFactory_hh__
+#define __AMathMLFactory_hh__
+
+#include "dom.hh"
+
+class AMathMLFactory
+{
+public:
+  AMathMLFactory(class ALogger& l) : logger(l), consumer(0) { };
+  AMathMLFactory(class ALogger& l, class AMathMLConsumer& c) : logger(l), consumer(&c) { };
+  virtual ~AMathMLFactory() { };
+
+  virtual void documentModified(class TDocument&) = 0;
+  virtual DOM::Document document(void) const = 0;
+
+protected:
+  class ALogger& logger;
+  class AMathMLConsumer* consumer;
+};
+
+#endif // __AMathMLFactory_hh__
index 2243426d2ecfcc4378b6f91022ac28474135b0fb..4fca8cf7651ba467d70766fa913b8d8147b4aa82 100644 (file)
@@ -5,16 +5,15 @@
 class APushLexer
 {
 public:
-  APushLexer(class APushParser& p) : parser(p) { };
+  APushLexer(class ALogger& l, class APushParser& p) : logger(l), parser(p) { };
   virtual ~APushLexer() { };
 
   virtual void push(char) = 0;
   virtual void reset(void) = 0;
   virtual bool error(void) const = 0;
-  //virtual void freeze(void);
-  //virtual void thaw(void);
 
 protected:
+  class ALogger&     logger;
   class APushParser& parser;
 };
 
index c2978106c275681372ca79dd776ac679ea4392a2..c7989614eaf4cf2feecb7043fb300dbda5c7206e 100644 (file)
@@ -1,3 +1,25 @@
+// Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>.
+//
+// This file is part of EdiTeX, an editor of mathematical
+// expressions based on TeX syntax
+// 
+// EdiTeX 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.
+//
+// EdiTeX 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 EdiTeX; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// 
+// For details, see the EdiTeX World-Wide-Web page,
+// http://helm.cs.unibo.it/editex, or send a mail to
+// <luca.padovani@cs.unibo.it>
 
 #ifndef __APushParser_hh__
 #define __APushParser_hh__
 class APushParser
 {
 public:
-  APushParser(void) { };
+  APushParser(class ALogger& l) : logger(l), factory(0) { };
+  APushParser(class ALogger& l, class AMathMLFactory& f) : logger(l), factory(&f) { };
+
   virtual ~APushParser() { };
   virtual void push(const TToken&) = 0;
-  virtual void setCursor(const std::string&) = 0;
+  virtual void setCursorHint(const std::string&) = 0;
+
+protected:
+  class ALogger& logger;
+  class AMathMLFactory* factory;
 };
 
 #endif // __APushParser_hh__
diff --git a/helm/DEVEL/mathml_editor/src/CLoggerConsole.cc b/helm/DEVEL/mathml_editor/src/CLoggerConsole.cc
new file mode 100644 (file)
index 0000000..194a6fa
--- /dev/null
@@ -0,0 +1,11 @@
+
+#include <iostream>
+
+#include "CLoggerConsole.hh"
+
+void
+CLoggerConsole::message(Level l, const std::string& msg)
+{
+  const char* ls[] = { "Error", "Warning", "Info", "Debug" };
+  cerr << "*** " << ls[l] << ": " << msg << endl;
+}
diff --git a/helm/DEVEL/mathml_editor/src/CLoggerConsole.hh b/helm/DEVEL/mathml_editor/src/CLoggerConsole.hh
new file mode 100644 (file)
index 0000000..a4da0d0
--- /dev/null
@@ -0,0 +1,16 @@
+
+#ifndef __CLoggerConsole_hh__
+#define __CLoggerConsole_hh__
+
+#include "ALogger.hh"
+
+class CLoggerConsole : public ALogger
+{
+public:
+  CLoggerConsole(void) { };
+
+protected:
+  virtual void message(Level, const std::string&);
+};
+
+#endif // __CLoggerConsole_hh__
diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc
new file mode 100644 (file)
index 0000000..244d364
--- /dev/null
@@ -0,0 +1,72 @@
+
+#include "dom.hh"
+#include "TNode.hh"
+#include "TDocument.hh"
+#include "CMathMLFactoryXSLT.hh"
+#include "AMathMLConsumer.hh"
+
+void
+CMathMLFactoryXSLT::documentModified(TDocument& doc)
+{
+  if (TNode dirty = doc.dirtyNode()) 
+    {
+      std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
+      if (result)
+       dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
+                                        DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
+      DOM::Document res = style.apply(doc.document(), dirtyId);
+      assert(res);
+      //style.save(doc.document(), stdout);
+      //style.save(res, stdout);
+      if (result)
+       {
+         DOM::Element root = res.get_documentElement();
+         assert(root);
+         assert(root.hasAttribute("xref"));
+
+         try
+           {
+             bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
+             assert(ok);
+           }
+         catch (DOM::DOMException& e)
+           {
+             cout << "!!!!!!!!!!!!!!!! EXCEPTION " << e.code << " " << e.msg << endl;
+             assert(0);
+           }
+       }
+      else
+       result = res;
+
+      doc.clearDirty();
+
+      if (consumer) consumer->documentModified(result);
+    }
+}
+
+bool
+CMathMLFactoryXSLT::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
+{
+  assert(e1);
+  assert(e2);
+  if (e1.getAttribute("xref") == id)
+    {
+      DOM::Node parent = e1.get_parentNode();
+      assert(parent);
+      parent.replaceChild(e2, e1);
+      return true;
+    }
+  else
+    {
+      DOM::Node p = e1.get_firstChild();
+      while (p)
+       {
+         while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
+         if (p)
+           if (subst(p, id, e2)) return true;
+           else p = p.get_nextSibling();
+       }
+      return false;
+    }
+}
+
diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh
new file mode 100644 (file)
index 0000000..70998e0
--- /dev/null
@@ -0,0 +1,23 @@
+
+#ifndef __CMathMLFactoryXSLT_hh__
+#define __CMathMLFactoryXSLT_hh__
+
+#include "AMathMLFactory.hh"
+
+class CMathMLFactoryXSLT : public AMathMLFactory
+{
+public:
+  CMathMLFactoryXSLT(class ALogger& l, const DOM::XSLTStylesheet& s) : AMathMLFactory(l), style(s) { };
+  CMathMLFactoryXSLT(class ALogger& l, class AMathMLConsumer& c, const DOM::XSLTStylesheet& s) : AMathMLFactory(l, c), style(s) { };
+
+  virtual void documentModified(class TDocument&);
+  virtual DOM::Document document(void) const { return result; };
+
+private:
+  static bool subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2);
+
+  const DOM::XSLTStylesheet& style;
+  DOM::Document result;
+};
+
+#endif // __CMathMLFactoryXSLT_hh__
index f440e528c880b94be193a409a9c685b49b87a084..c0afe28ee379ed79082c1ffa72dd29e6dd19a5b0 100644 (file)
@@ -4,16 +4,22 @@ lib_LTLIBRARIES = libeditex.la
 libeditex_la_LDFLAGS = -version-info @EDITEX_VERSION_INFO@
 
 libeditex_la_SOURCES = \
+  CLoggerConsole.cc \
   TPushLexer.cc \
   TPushParser.cc \
+  CMathMLFactoryXSLT.cc \
   TDictionary.cc \
   TDocument.cc \
   TNode.cc \
   TTokenizer.cc
 
 pkginclude_HEADERS = \
+  ALogger.hh \
+  CLoggerConsole.hh \
   APushLexer.hh \
   APushParser.hh \
+  AMathMLFactory.hh \
+  CMathMLFactoryXSLT.hh \
   TPushLexer.hh \
   TPushParser.hh \
   TTokenizer.hh \
index b614c8f92382e42239629c6c86b317ce1c7f9469..0592ae444bdfcfc41f3ac742a7463e2e4888baff 100644 (file)
@@ -89,10 +89,10 @@ lib_LTLIBRARIES = libeditex.la
 
 libeditex_la_LDFLAGS = -version-info @EDITEX_VERSION_INFO@
 
-libeditex_la_SOURCES =    TPushLexer.cc   TPushParser.cc   TDictionary.cc   TDocument.cc   TNode.cc   TTokenizer.cc
+libeditex_la_SOURCES =    CLoggerConsole.cc   TPushLexer.cc   TPushParser.cc   CMathMLFactoryXSLT.cc   TDictionary.cc   TDocument.cc   TNode.cc   TTokenizer.cc
 
 
-pkginclude_HEADERS =    APushLexer.hh   APushParser.hh   TPushLexer.hh   TPushParser.hh   TTokenizer.hh   TDictionary.hh   TDocument.hh   TNode.hh   TListener.hh   dom.hh
+pkginclude_HEADERS =    ALogger.hh   CLoggerConsole.hh   APushLexer.hh   APushParser.hh   AMathMLFactory.hh   CMathMLFactoryXSLT.hh   TPushLexer.hh   TPushParser.hh   TTokenizer.hh   TDictionary.hh   TDocument.hh   TNode.hh   TListener.hh   dom.hh
 
 
 INCLUDES = $(GMETADOM_CFLAGS) $(GDOMEXSLT_CFLAGS)
@@ -105,8 +105,9 @@ LTLIBRARIES =  $(lib_LTLIBRARIES)
 DEFS = @DEFS@ -I. -I$(srcdir) -I..
 LIBS = @LIBS@
 libeditex_la_LIBADD = 
-libeditex_la_OBJECTS =  TPushLexer.lo TPushParser.lo TDictionary.lo \
-TDocument.lo TNode.lo TTokenizer.lo
+libeditex_la_OBJECTS =  CLoggerConsole.lo TPushLexer.lo TPushParser.lo \
+CMathMLFactoryXSLT.lo TDictionary.lo TDocument.lo TNode.lo \
+TTokenizer.lo
 CXXFLAGS = @CXXFLAGS@
 CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
 LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
@@ -121,8 +122,9 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
 
 TAR = tar
 GZIP_ENV = --best
-DEP_FILES =  .deps/TDictionary.P .deps/TDocument.P .deps/TNode.P \
-.deps/TPushLexer.P .deps/TPushParser.P .deps/TTokenizer.P
+DEP_FILES =  .deps/CLoggerConsole.P .deps/CMathMLFactoryXSLT.P \
+.deps/TDictionary.P .deps/TDocument.P .deps/TNode.P .deps/TPushLexer.P \
+.deps/TPushParser.P .deps/TTokenizer.P
 SOURCES = $(libeditex_la_SOURCES)
 OBJECTS = $(libeditex_la_OBJECTS)
 
index dcaf1d627562f072f8a535fe1a8f62a6edb226fb..8c16d2ba91327bf0dba38ed1ecc3cb554a905276 100644 (file)
@@ -4,6 +4,7 @@
 #include "dom.hh"
 #include "TDictionary.hh"
 #include "TTokenizer.hh"
+#include "CLoggerConsole.hh"
 
 static TDictionary::Entry undefinedEntry;
 
@@ -18,7 +19,8 @@ TDictionary::load(const char* uri)
   DOM::Element root = doc.get_documentElement();
   assert(root);
 
-  TTokenizer tokenizer;
+  CLoggerConsole logger;
+  TTokenizer tokenizer(logger);
 
   for (DOM::Node p = root.get_firstChild(); p; p = p.get_nextSibling())
     if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "entry")
index 4c3bbbaea6bfca6d3b2b1fa1c2e94b49fce9f527..a7b5c8d3a5d2cb57fcd5adc11f79eb6e61ad91ab 100644 (file)
@@ -11,8 +11,8 @@ TDocument::TDocument()
   DOM::DocumentType dt;
   doc = di.createDocument(TML_NS_URI, "tml:tex", dt);
   DOM::Element root = doc.get_documentElement();
-  root.setAttributeNS(XMLNS_NS_URI, "xmlns:tml", TML_NS_URI);
   assert(root);
+  root.setAttributeNS(XMLNS_NS_URI, "xmlns:tml", TML_NS_URI);
 
   DOM::EventTarget et(doc);
   assert(et);
index 466ee2bd8b48c51644a4c901d16f7a178d59c15f..1d25abbe98edff1fa8299e0eb82fc7585b6397d7 100644 (file)
@@ -3,7 +3,7 @@
 #include "TPushLexer.hh"
 #include "APushParser.hh"
 
-TPushLexer::TPushLexer(APushParser& p) : APushLexer(p)
+TPushLexer::TPushLexer(ALogger& l, APushParser& p) : APushLexer(l, p)
 {
   state = ACCEPT;
 }
@@ -133,10 +133,10 @@ TPushLexer::push(char ch)
 
   switch (state)
     {
-    case ESCAPE: parser.setCursor("\\"); break;
-    case MACRO: parser.setCursor("\\" + buffer); break;
-    case PARAMETER: parser.setCursor("#"); break;
-    default: parser.setCursor("?"); break;
+    case ESCAPE: parser.setCursorHint("\\"); break;
+    case MACRO: parser.setCursorHint("\\" + buffer); break;
+    case PARAMETER: parser.setCursorHint("#"); break;
+    default: parser.setCursorHint(""); break;
     }
 }
 
index 6fd212a3de319e19f102f4f5b13722a0cf2a0e23..a12a9bf63112bbdf6a7a80a6f4f82e1684ee5f29 100644 (file)
@@ -9,7 +9,7 @@
 class TPushLexer : public APushLexer
 {
 public:
-  TPushLexer(class APushParser&);
+  TPushLexer(class ALogger&, class APushParser&);
   virtual ~TPushLexer() { };
 
   virtual void push(char);
index d3dd893d73c494ad8b6648fd4ae74242b557349f..325b9aa3c129f9a9bd31500aeec01ed6850184f1 100644 (file)
@@ -1,13 +1,14 @@
 
+#include "ALogger.hh"
 #include "TPushParser.hh"
-#include "TListener.hh"
+#include "AMathMLFactory.hh"
 
-TPushParser::TPushParser(const TDictionary& d) : dictionary(d), listener(0)
+TPushParser::TPushParser(ALogger& l, const TDictionary& d) : APushParser(l), dictionary(d)
 {
   init();
 }
 
-TPushParser::TPushParser(const TDictionary& d, TListener& l) : dictionary(d), listener(&l)
+TPushParser::TPushParser(ALogger& l, AMathMLFactory& f, const TDictionary& d) : APushParser(l, f), dictionary(d)
 {
   init();
 }
@@ -1178,7 +1179,7 @@ TPushParser::push(const TToken& token)
           cout << "ignored token" << endl;
         }
       
-      if (listener) listener->callback(doc); //it shoul be repristened if you remove the comment in the else above
+      //if (listener) listener->callback(doc); //it shoul be repristened if you remove the comment in the else above
 
     } // this end corresponds to the if ((doc.root().first() && doc.root().first().is("math")) || token.category == TToken::SHIFT)
   else
@@ -1188,8 +1189,7 @@ TPushParser::push(const TToken& token)
       cout << "push: ignored token...you have to enter in math mode...insert $" << endl;
     }
 
-
-  //if (listener) listener->callback(doc);
+  if (factory) factory->documentModified(doc);
 
   if (frames.empty()) cout << "stack vuoto" << endl;
   else cout << "stack non vuoto" << endl;
@@ -1231,8 +1231,8 @@ TPushParser::advance(const TNode& node)
 }
 
 void
-TPushParser::setCursor(const std::string& c)
+TPushParser::setCursorHint(const std::string& c)
 {
   cursor["val"] = c;
-  if (listener) listener->callback(doc);
+  if (factory) factory->documentModified(doc);
 }
index 951fb874ab79a0b85e805045cbf0b48410198548..09bfe713db9a94321fa1f3873bc4d67fccff8f32 100644 (file)
 class TPushParser : public APushParser
 {
 public:
-  TPushParser(const class TDictionary&);
-  TPushParser(const class TDictionary&, class TListener&);
+  TPushParser(class ALogger&, const class TDictionary&);
+  TPushParser(class ALogger&, class AMathMLFactory&, const class TDictionary&);
   virtual ~TPushParser();
 
   virtual void push(const TToken&);
-  virtual void setCursor(const std::string&);
+  virtual void setCursorHint(const std::string&);
 
+protected:
   TDocument document(void) const { return doc; }
 
 private:
@@ -61,13 +62,10 @@ private:
   };
 
   std::stack<Frame> frames;
-  //std::list<TToken> buffer;
   unsigned  nextId;
   TDocument doc;
   TNode     cursor;
-
   const class TDictionary& dictionary;
-  class TListener* listener;
 };
 
 #endif // __TPushParser_hh__
index 93cadefd7efba5ec1cd6db38e1eb529393c5c0f5..cfa10ec71cb1618fa4f7d88755624049d0d927b8 100644 (file)
@@ -7,7 +7,7 @@
 std::vector<TToken>
 TTokenizer::tokenize(const std::string& s)
 {
-  TPushLexer lexer(*this);
+  TPushLexer lexer(logger, *this);
 
   tokens.clear();
   for (std::string::const_iterator p = s.begin();
index d0a54bf2869ce16a268ceda0604b876e3f045b0b..54618c88b1e4c10120f31fc4cc159afacc47dd30 100644 (file)
 class TTokenizer : private APushParser
 {
 public:
-  TTokenizer(void) { };
+  TTokenizer(class ALogger& l) : APushParser(l) { };
 
   std::vector<TToken> tokenize(const std::string&);
 
 private:
   virtual void push(const TToken&);
-  virtual void setCursor(const std::string&) { };
+  virtual void setCursorHint(const std::string&) { };
 
   std::list<TToken> tokens;
 };
index f2c42dba04883ca11b8600abc590868aed164175..a2058302efdca768eb464e33eab22cfa6994995c 100644 (file)
@@ -3,6 +3,7 @@
 #define __dom_hh__
 
 #include <GdomeSmartDOM.hh>
+#include <GdomeSmartDOMXSLT.hh>
 
 namespace DOM = GdomeSmartDOM;
 
diff --git a/helm/DEVEL/mathml_editor/test/.cvsignore b/helm/DEVEL/mathml_editor/test/.cvsignore
new file mode 100644 (file)
index 0000000..6a37f8d
--- /dev/null
@@ -0,0 +1,6 @@
+.deps
+.libs
+Makefile
+Makefile.in
+editor
+test
index 24ebd7c425067584b8b174cd76b51d44a1678a6f..a1fef0cf0f31fedb7b706b99384f74b643d5e805 100644 (file)
@@ -1,7 +1,6 @@
 
-noinst_PROGRAMS = test editor
+noinst_PROGRAMS = editor
 
-test_SOURCES = main.cc
 editor_SOURCES = editor.cc guiGTK.c aux.cc
 
 LDADDS = \
@@ -10,7 +9,6 @@ LDADDS = \
   $(GTKMATHVIEW_LIBS) \
   $(top_builddir)/src/.libs/libeditex.a
 
-test_LDADD = $(LDADDS)
 editor_LDADD = $(LDADDS)
 
 INCLUDES = \
index 3c69a2a1cc8d7ac4f6853bb8f5097dd48d17eb4c..2bf438dc59736b397e75a7e898db5040d1d86559 100644 (file)
@@ -85,15 +85,13 @@ RANLIB = @RANLIB@
 STRIP = @STRIP@
 VERSION = @VERSION@
 
-noinst_PROGRAMS = test editor
+noinst_PROGRAMS = editor
 
-test_SOURCES = main.cc
 editor_SOURCES = editor.cc guiGTK.c aux.cc
 
 LDADDS =    $(GMETADOM_LIBS)   $(GDOMEXSLT_LIBS)   $(GTKMATHVIEW_LIBS)   $(top_builddir)/src/.libs/libeditex.a
 
 
-test_LDADD = $(LDADDS)
 editor_LDADD = $(LDADDS)
 
 INCLUDES =    $(GMETADOM_CFLAGS)   $(GDOMEXSLT_CFLAGS)   $(GTKMATHVIEW_CFLAGS)   -I$(top_srcdir)/src
@@ -101,15 +99,12 @@ INCLUDES =    $(GMETADOM_CFLAGS)   $(GDOMEXSLT_CFLAGS)   $(GTKMATHVIEW_CFLAGS)
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = ../config.h
 CONFIG_CLEAN_FILES = 
-noinst_PROGRAMS =  test$(EXEEXT) editor$(EXEEXT)
+noinst_PROGRAMS =  editor$(EXEEXT)
 PROGRAMS =  $(noinst_PROGRAMS)
 
 
 DEFS = @DEFS@ -I. -I$(srcdir) -I..
 LIBS = @LIBS@
-test_OBJECTS =  main.$(OBJEXT)
-test_DEPENDENCIES =  $(top_builddir)/src/.libs/libeditex.a
-test_LDFLAGS = 
 editor_OBJECTS =  editor.$(OBJEXT) guiGTK.$(OBJEXT) aux.$(OBJEXT)
 editor_DEPENDENCIES =  $(top_builddir)/src/.libs/libeditex.a
 editor_LDFLAGS = 
@@ -129,9 +124,9 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
 
 TAR = tar
 GZIP_ENV = --best
-DEP_FILES =  .deps/aux.P .deps/editor.P .deps/guiGTK.P .deps/main.P
-SOURCES = $(test_SOURCES) $(editor_SOURCES)
-OBJECTS = $(test_OBJECTS) $(editor_OBJECTS)
+DEP_FILES =  .deps/aux.P .deps/editor.P .deps/guiGTK.P
+SOURCES = $(editor_SOURCES)
+OBJECTS = $(editor_OBJECTS)
 
 all: all-redirect
 .SUFFIXES:
@@ -191,10 +186,6 @@ distclean-libtool:
 
 maintainer-clean-libtool:
 
-test$(EXEEXT): $(test_OBJECTS) $(test_DEPENDENCIES)
-       @rm -f test$(EXEEXT)
-       $(CXXLINK) $(test_LDFLAGS) $(test_OBJECTS) $(test_LDADD) $(LIBS)
-
 editor$(EXEEXT): $(editor_OBJECTS) $(editor_DEPENDENCIES)
        @rm -f editor$(EXEEXT)
        $(CXXLINK) $(editor_LDFLAGS) $(editor_OBJECTS) $(editor_LDADD) $(LIBS)
index e12700e3a89662439e5e24db88e698852fb96f90..9d548289c6a2625491060ef5b83ae543a492c369 100644 (file)
 
-#include "TNode.hh"
-#include "TToken.hh"
-#include "TDocument.hh"
+#include "dom.hh"
 #include "TPushParser.hh"
 #include "TPushLexer.hh"
 #include "TDictionary.hh"
-#include "TListener.hh"
-#include <GdomeSmartDOMXSLT.hh>
+#include "CLoggerConsole.hh"
+#include "CMathMLFactoryXSLT.hh"
+#include "AMathMLConsumer.hh"
 
 #include "guiGTK.h"
 
-class MyResultListener : public DOM::EventListener
-{
-public:
-  MyResultListener(const std::string& s) : msg(s) { };
-
-  virtual void handleEvent(const DOM::Event&);
-
-private:
-  const std::string msg;
-};
-
-void
-MyResultListener::handleEvent(const DOM::Event& ev)
-{
-  cout << "RECEIVED EVENT: " << ev.get_type() << " " << msg << " ";
-  const DOM::MutationEvent& me(ev);
-  assert(me);
-  const DOM::Node target(me.get_target());
-  assert(target);
-  cout << "target = " << target.get_nodeName() << " " << target.get_nodeType() << endl;
-}
-
-MyResultListener l1("?");
-
 TDictionary dictionary;
-DOM::Document result;
 
 extern void *parseMathMLFile(char *);
 
-bool
-subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
-{
-  assert(e1);
-  assert(e2);
-  if (e1.getAttribute("xref") == id)
-    {
-      DOM::Node parent = e1.get_parentNode();
-      assert(parent);
-      DOM::Node next = e1.get_nextSibling();
-      parent.removeChild(e1);
-      parent.insertBefore(e2, next);
-      //parent.replaceChild(e2, e1);
-      return true;
-    }
-  else
-    {
-      DOM::Node p = e1.get_firstChild();
-      while (p)
-       {
-         while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
-         if (p)
-           if (subst(p, id, e2)) return true;
-           else p = p.get_nextSibling();
-       }
-      return false;
-    }
-}
-
-class MyListener : public TListener
+class CMathMLConsumer : public AMathMLConsumer
 {
 public:
-  MyListener(const DOM::XSLTStylesheet& s) : style(s) { };
+  CMathMLConsumer(void) { firstTime = true; };
 
-  void callback(TDocument& doc)
+  virtual void documentModified(const DOM::Document& result)
   {
-    cout << "listener callback " << static_cast<GdomeNode*>(doc.document()) << endl;
-    TNode dirty = doc.dirtyNode();
-    if (dirty) 
+    if (firstTime)
       {
-       cout << "recreating subtree with id " << std::string(dirty["id"]) << endl;
-       std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
-       if (result)
-         dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
-                                          DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
-
-       DOM::Document res = style.apply(doc.document(), dirtyId);
-       assert(res);
-       style.save(doc.document(), stdout);
-       //style.save(res, stdout);
-       if (result)
-         {
-           cout << "REPLACING A FRAGMENT OF THE DOCUMENT" << endl;
-           DOM::Element root = res.get_documentElement();
-           assert(root);
-           assert(root.hasAttribute("xref"));
-
-           if (result.get_documentElement().getAttribute("xref") == root.getAttribute("xref"))
-             {
-               cout << "REPLACING ROOT" << endl;
-               result.replaceChild(result.importNode(root, true), result.get_documentElement());
-#if 0
-               // the following remove should not be necessary
-               // according to the spec replaceChild should work just fine
-               result.removeChild(result.get_documentElement());
-               result.appendChild(result.importNode(root, true));
-#endif
-             }
-           else
-             try
-               {
-                 cout << "before" << endl;
-                 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
-                 assert(ok);
-                 cout << "after" << endl;
-               }
-             catch (DOM::DOMException e)
-               {
-                 cout << "!!!!!!!!!!!!!!!! EXCEPTION " << e.code << " " << e.msg << endl;
-                 assert(0);
-               }
-         }
-       else
-         {
-           cout << "SETTING THE DOCUMENT FOR THE FIRST TIME" << endl;
-           result = res;
-
-           DOM::EventTarget et(result);
-           assert(et);
-           cout << "SETTING EVENT LISTENER (EDITOR) ON " << static_cast<GdomeNode*>(result) << endl;
-           et.addEventListener("DOMSubtreeModified", l1, true);
-
-            if (GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(result))) < 0)
-             cerr << "c'e' stato un errore" << endl;
-         }
-       style.save(result, stdout);
-
-       doc.clearDirty();
+       if (GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(result))) < 0)
+         cerr << "c'e' stato un errore" << endl;
+       firstTime = false;
       }
   }
 
 private:
-  const DOM::XSLTStylesheet& style;
+  bool firstTime;
 };
 
 struct Context
@@ -150,11 +38,7 @@ struct Context
 
   void send(void)
   {
-    if (i < buffer.length())
-      {
-       cout << "document is " << static_cast<GdomeNode*>(result) << endl;
-       lexer.push(buffer[i++]);
-      }
+    if (i < buffer.length()) lexer.push(buffer[i++]);
     else lexer.push('\n');
   }
 
@@ -184,17 +68,19 @@ push_char(Context* context, gchar ch)
 
 main(int argc, char* argv[])
 {
-  cout << "loading the dictionary..." << endl;
+  CLoggerConsole logger;
+  logger.info("loading the dictionary...");
   dictionary.load("dictionary.xml");
 
-  cout << "loading the stylesheet..." << endl;
+  logger.info("loading the stylesheet...");
   DOM::DOMImplementation di;
   DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
   DOM::XSLTStylesheet style(docStyle);
-  
-  MyListener listener(style);
-  TPushParser parser(dictionary, listener);
-  TPushLexer lexer(parser);
+
+  CMathMLConsumer consumer;
+  CMathMLFactoryXSLT factory(logger, consumer, style);
+  TPushParser parser(logger, factory, dictionary);
+  TPushLexer lexer(logger, parser);
 
 #if 0
   lexer.push('$');
@@ -211,7 +97,6 @@ main(int argc, char* argv[])
 
   Context context("", lexer);
 
-  cout << "passing context " << &context << endl;
   GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
   GUI_run();
   GUI_uninit();
index 88b85f8b585145fc5ded90c713aa3cdd37690996..cd1c7c878c4f8b117d68aefcde16695dd6534c8f 100644 (file)
@@ -340,7 +340,7 @@ selection_parent(GtkWidget* widget, gpointer data)
       gdome_el_unref(root_selected, &exc);
       g_assert(exc == 0);
       root_selected = parent;
-      gtk_math_view_set_selection(GTK_MATH_VIEW(main_area), root_selected);
+      /* gtk_math_view_set_selection(GTK_MATH_VIEW(main_area), root_selected); */
     }
 }
 
@@ -350,7 +350,7 @@ selection_reset(GtkWidget* widget, gpointer data)
   if (root_selected != NULL)
     {
       GdomeException exc = 0;
-      gtk_math_view_reset_selection(GTK_MATH_VIEW(main_area), root_selected);
+      /* gtk_math_view_reset_selection(GTK_MATH_VIEW(main_area), root_selected); */
       gdome_el_unref(root_selected, &exc);
       g_assert(exc == 0);
       root_selected = NULL;
@@ -481,7 +481,7 @@ selection_changed(GtkMathView* math_view, GdomeElement* first, GdomeElement* las
 
       root_selected = find_common_ancestor(first, last);
 /*       printf("selecting root %p\n", first, last, root_selected); */
-      gtk_math_view_set_selection(math_view, root_selected);
+      /* gtk_math_view_set_selection(math_view, root_selected); */
       g_assert(exc == 0);
     }
 }
diff --git a/helm/DEVEL/mathml_editor/test/main.cc b/helm/DEVEL/mathml_editor/test/main.cc
deleted file mode 100644 (file)
index 3122d52..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-
-#include "TNode.hh"
-#include "TToken.hh"
-#include "TDocument.hh"
-#include "TPushParser.hh"
-#include "TPushLexer.hh"
-#include "TDictionary.hh"
-#include "TListener.hh"
-#include <GdomeSmartDOMXSLT.hh>
-
-TDictionary dictionary;
-DOM::Document result;
-
-bool
-subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2)
-{
-  assert(e1);
-  assert(e2);
-  if (e1.getAttribute("xref") == id)
-    {
-      DOM::Node parent = e1.get_parentNode();
-      assert(parent);
-      parent.replaceChild(e2, e1);
-      return true;
-    }
-  else
-    {
-      DOM::Node p = e1.get_firstChild();
-      while (p)
-       {
-         while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
-         if (p)
-           if (subst(p, id, e2)) return true;
-           else p = p.get_nextSibling();
-       }
-      return false;
-    }
-}
-
-#if 0
-bool
-subst(const DOM::Node& parent, const DOM::GdomeString& id, const DOM::Element& newElem)
-{
-  assert(parent);
-  assert(newElem);
-
-  DOM::Node p = parent.get_firstChild();
-  while (p)
-    {
-      while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling();
-      if (p)
-       {
-         DOM::Element el = p;
-         assert(el);
-         if (el.getAttribute("xref") == id)
-           {
-             parent.replaceChild(el, newElem);
-             return true;
-           }
-         else if (subst(el, id, newElem))
-           return true;
-         else
-           p = p.get_nextSibling();
-       }
-    }
-
-  return false;
-}
-#endif
-
-class MyListener : public TListener
-{
-public:
-  MyListener(const DOM::XSLTStylesheet& s) : style(s) { };
-
-  void callback(TDocument& doc)
-  {
-    TNode dirty = doc.dirtyNode();
-    if (dirty) 
-      {
-       cout << "recreating subtree with id " << std::string(dirty["id"]) << endl;
-       std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > dirtyId;
-       if (result)
-         dirtyId.push_back(std::make_pair(DOM::GdomeString("id"),
-                                          DOM::GdomeString("'" + std::string(dirty["id"]) + "'")));
-       DOM::Document res = style.apply(doc.document(), dirtyId);
-       assert(res);
-       style.save(res, stdout);
-       if (result)
-         {
-           DOM::Element root = res.get_documentElement();
-           assert(root);
-           assert(root.hasAttribute("xref"));
-
-           if (result.get_documentElement().getAttribute("xref") == root.getAttribute("xref"))
-             {
-               // the following remove should not be necessary
-               // according to the spec replaceChild should work just fine
-               result.removeChild(result.get_documentElement());
-               result.appendChild(result.importNode(root, true));
-             }
-           else
-             try
-               {
-                 cout << "before" << endl;
-                 bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true));
-                 assert(ok);
-                 cout << "after" << endl;
-               }
-             catch (DOM::DOMException e)
-               {
-                 cerr << "exception " << e.code << " " << e.msg << endl;
-                 assert(0);
-               }
-         }
-       else
-         result = res;
-
-       doc.clearDirty();
-      }
-  }
-
-private:
-  const DOM::XSLTStylesheet& style;
-};
-
-main(int argc, char* argv[])
-{
-  if (argc != 2)
-    {
-      cerr << "specify a string, please" << endl;
-      return -1;
-    }
-
-  cout << "loading the dictionary..." << endl;
-  dictionary.load("dictionary.xml");
-
-  cout << "loading the stylesheet..." << endl;
-  DOM::DOMImplementation di;
-  DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
-  DOM::XSLTStylesheet style(docStyle);
-  
-  MyListener listener(style);
-  TPushParser parser(dictionary, listener);
-  TPushLexer lexer(parser);
-
-  std::string s = argv[1];
-  for (unsigned long i = 0; i < s.length(); i++)
-    lexer.push(s[i]);
-  lexer.push('\n');
-  
-  cout << "finished" << endl;
-  di.saveDocumentToFile(result, "result.xml", GDOME_SAVE_LIBXML_INDENT);
-
-  cout << "done" << endl;
-
-  parser.document().serialize("output.xml");
-}
index 034c5073a1920e147d3b20f8f75573fa191279ae..9054b9c997ffbaf020b6378f819c373384ed3fbd 100644 (file)
@@ -68,7 +68,7 @@
     </m:mo>
   </xsl:template>
 
-  <xsl:template match="tml:cursor">
+  <xsl:template name="cursor">
     <xsl:choose>
       <xsl:when test="substring(@val,1,1)='\'">
         <m:mrow>
       </xsl:when>
       <xsl:otherwise>
         <m:mtext mathcolor="blue">
-          <xsl:if test="@id">
-            <xsl:attribute name="xref">
-              <xsl:value-of select="@id"/>
-            </xsl:attribute>
-          </xsl:if>
-         <xsl:value-of select="@val"/>
-       </m:mtext>
+         <xsl:if test="@id">
+           <xsl:attribute name="xref">
+             <xsl:value-of select="@id"/>
+           </xsl:attribute>
+         </xsl:if>
+        I
+        </m:mtext>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="tml:cursor">
+    <xsl:param name="annotation" select="/.."/>
+    <xsl:choose>
+      <xsl:when test="$annotation">
+        <m:msub>
+         <xsl:call-template name="cursor"/>
+         <m:mtext>
+           <xsl:value-of select="$annotation"/>
+         </m:mtext>
+       </m:msub>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="cursor"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
   </xsl:template>
 
   <xsl:template match="tml:g">
+    <xsl:param name="annotation" select="/.."/>
     <xsl:choose>
       <xsl:when test="not(@id) and count(*) = 1">
-        <xsl:apply-templates select="*[1]"/>
+        <xsl:apply-templates select="*[1]">
+         <xsl:with-param name="annotation" select="$annotation"/>
+       </xsl:apply-templates>
       </xsl:when>
       <xsl:when test="tml:cursor">
        <m:mstyle mathbackground="#e0e0e0">
             </xsl:attribute>
          </xsl:if>
          <m:mrow>
-           <xsl:apply-templates select="*"/>
+           <xsl:apply-templates select="*">
+             <xsl:with-param name="annotation" select="$annotation"/>
+           </xsl:apply-templates>
          </m:mrow>
        </m:mstyle>
       </xsl:when>
               <xsl:value-of select="@id"/>
             </xsl:attribute>
          </xsl:if>
-         <xsl:apply-templates select="*"/>
+         <xsl:apply-templates select="*">
+           <xsl:with-param name="annotation" select="$annotation"/>
+         </xsl:apply-templates>
        </m:mrow>
       </xsl:otherwise>
     </xsl:choose>
         </xsl:attribute>
       </xsl:if>
       <xsl:apply-templates select="*[1]"/>
+      <xsl:if test="tml:g/tml:cursor">
+        <m:msub>
+          <m:mtext mathcolor="#808080">}</m:mtext>
+         <m:mtext><xsl:value-of select="@name"/></m:mtext>
+        </m:msub>
+      </xsl:if>
     </m:mstyle>
   </xsl:template>