]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/ITPushLexer.cc
Added the completion of the macro's name.
[helm.git] / helm / DEVEL / mathml_editor / src / ITPushLexer.cc
diff --git a/helm/DEVEL/mathml_editor/src/ITPushLexer.cc b/helm/DEVEL/mathml_editor/src/ITPushLexer.cc
new file mode 100644 (file)
index 0000000..b4d1b6c
--- /dev/null
@@ -0,0 +1,44 @@
+#include <list>
+#include <string>
+
+#include "ALogger.hh"
+#include "TToken.hh"
+#include "ITPushLexer.hh"
+#include "APushParser.hh"
+#include "TDictionary.hh"
+
+ITPushLexer::ITPushLexer(ALogger& l, APushParser& p, TDictionary& d) : TPushLexer(l, p), dictionary(d)
+{
+  state = ACCEPT;
+}
+
+bool
+ITPushLexer::complete()
+{
+  if (state == MACRO)
+    {
+      std::list<std::string> complete_list;
+      std::string new_buffer = dictionary.complete(buffer, complete_list);
+
+      if (!complete_list.size())
+        {
+          // no matching macro
+          logger.warning("wrong prefix: nothing to complete");
+        }
+      else if (complete_list.size() == 1)
+        {
+          // good! we have found the macro
+          buffer = new_buffer;
+        }
+      else
+        {
+          // we have more than one matching macro
+          logger.warning("prefix not sufficient");
+          buffer = new_buffer;
+        }
+
+      displayCursor();
+      return true;
+    }
+  else return false;
+}