]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/TPushLexer.cc
* this is a large commit
[helm.git] / helm / DEVEL / mathml_editor / src / TPushLexer.cc
index 1d25abbe98edff1fa8299e0eb82fc7585b6397d7..c8d04f1bd4354401a4de38b2b83c18c101d231fb 100644 (file)
@@ -55,7 +55,6 @@ TPushLexer::push(char ch)
     case ACCEPT:
       if (ch == '\\') state = ESCAPE;
       else if (ch == '#') state = PARAMETER;
-      else if (ch == '\b') parser.push(TToken(TToken::GDELETE));
       else if (ch == -1) ;
       else transaction(ch, ACCEPT);
       break;
@@ -65,10 +64,6 @@ TPushLexer::push(char ch)
          buffer.push_back(ch);
          state = MACRO;
        }
-      else if (ch == '\b')
-        {
-         state = ACCEPT;
-       }
       else if (ch == -1) error();
       else
        {
@@ -89,11 +84,6 @@ TPushLexer::push(char ch)
          buffer.erase();
          state = PARAMETER;
        }
-      else if (ch == '\b')
-       {
-         buffer.erase(buffer.length() - 1, 1);
-         if (buffer.length() == 0) state = ESCAPE;
-       }
       else if (isalpha(ch))
        buffer.push_back(ch);
       else if (ch == -1)
@@ -114,7 +104,6 @@ TPushLexer::push(char ch)
       if (ch == '\\') state = ESCAPE;
       else if (ch == '#') state = PARAMETER;
       else if (isspace(ch)) ;
-      else if (ch == '\b') parser.push(TToken(TToken::GDELETE));
       else if (ch == -1) state = ACCEPT;
       else transaction(ch, ACCEPT);
       break;
@@ -140,6 +129,45 @@ TPushLexer::push(char ch)
     }
 }
 
+void
+TPushLexer::drop(bool alt)
+{
+  std::string restore = "";
+
+  switch (state)
+    {
+    case ACCEPT:
+    case IGNORE_SPACE:
+      restore = parser.drop();
+      if (restore.length() > 0 && restore[0] == '\\')
+       {
+         buffer = std::string(restore, 1, restore.length() - 1);
+         state = (buffer.length() > 0) ? MACRO : ESCAPE;
+       }
+      break;
+    case ESCAPE:
+      state = ACCEPT;
+      break;
+    case MACRO:
+      if (alt) buffer.erase();
+      else buffer.erase(buffer.length() - 1, 1);
+      if (buffer.length() == 0) state = ESCAPE;
+      break;
+    case PARAMETER:
+    default:
+      assert(0);
+      break;
+    }
+
+  switch (state)
+    {
+    case ESCAPE: parser.setCursorHint("\\"); break;
+    case MACRO: parser.setCursorHint("\\" + buffer); break;
+    case PARAMETER: parser.setCursorHint("#"); break;
+    default: parser.setCursorHint(""); break;
+    }
+}
+
 bool
 TPushLexer::error() const
 {