]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/TDictionary.cc
* code cleanup
[helm.git] / helm / DEVEL / mathml_editor / src / TDictionary.cc
index 303d743d441aa3399dc8639eb17354e9284bff14..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")
@@ -134,7 +136,7 @@ TDictionary::load(const char* uri)
          {
            if (entry.cls != MACRO)
              cerr << "WARNING: `" << name << "' table ignored for non-macro" << endl;
-           
+
            std::istringstream is(el.getAttribute("table"));
            unsigned table;
            is >> table;
@@ -166,3 +168,32 @@ TDictionary::Entry::paramDelimited(unsigned i) const
   // AND the next argument is not a parameter
   return i + 1 < pattern.size() && pattern[i + 1].category != TToken::PARAMETER;
 }
+
+bool
+TDictionary::Entry::lastDelimiter(unsigned i) const
+{
+  assert(i < pattern.size());
+  assert(pattern[i].category != TToken::PARAMETER);
+  // a token is the last delimiter if it is the last token 
+  // of the pattern or if the next token is a parameter)
+  return i + 1 == pattern.size() || pattern[i + 1].category == TToken::PARAMETER;
+}
+
+unsigned
+TDictionary::Entry::previousParam(unsigned i) const
+{
+  // this method return the position in the pattern of the 
+  // parameter placed in a position preceding i.
+  // If no preceding i parameter present, the method return
+  // pattern.size().
+  // To know the position of the last parameter, call this 
+  // method with i == pattern.size()
+  unsigned j = i - 1;
+
+  while (pattern[j].category != TToken::PARAMETER)
+    {
+      if (j) j--;
+      else return pattern.size();
+    }
+  return j;
+}