]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/TDictionary.cc
Now it's possible to insert and delete control sequence with arguments
[helm.git] / helm / DEVEL / mathml_editor / src / TDictionary.cc
index 303d743d441aa3399dc8639eb17354e9284bff14..dcaf1d627562f072f8a535fe1a8f62a6edb226fb 100644 (file)
@@ -134,7 +134,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 +166,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;
+}