]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/ILPushLexer.cc
Added the completion of the macro's name.
[helm.git] / helm / DEVEL / mathml_editor / src / ILPushLexer.cc
diff --git a/helm/DEVEL/mathml_editor/src/ILPushLexer.cc b/helm/DEVEL/mathml_editor/src/ILPushLexer.cc
new file mode 100644 (file)
index 0000000..8a2777f
--- /dev/null
@@ -0,0 +1,45 @@
+
+#include <list>
+#include <string>
+
+#include "ALogger.hh"
+#include "TToken.hh"
+#include "ILPushLexer.hh"
+#include "APushParser.hh"
+#include "TDictionary.hh"
+
+ILPushLexer::ILPushLexer(ALogger& l, APushParser& p, TDictionary& d) : LPushLexer(l, p), dictionary(d)
+{
+  state = ACCEPT;
+}
+
+bool
+ILPushLexer::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;
+}