]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/src/ILPushLexer.cc
ocaml 3.09 transition
[helm.git] / helm / DEVEL / mathml_editor / src / ILPushLexer.cc
1
2 #include <list>
3 #include <string>
4
5 #include "ALogger.hh"
6 #include "TToken.hh"
7 #include "ILPushLexer.hh"
8 #include "APushParser.hh"
9 #include "TDictionary.hh"
10
11 ILPushLexer::ILPushLexer(ALogger& l, APushParser& p, TDictionary& d) : LPushLexer(l, p), dictionary(d)
12 {
13   state = ACCEPT;
14 }
15
16 bool
17 ILPushLexer::complete()
18 {
19   if (state == MACRO)
20     {
21       std::list<std::string> complete_list;
22       std::string new_buffer = dictionary.complete(buffer, complete_list);
23
24       if (!complete_list.size())
25         {
26           // no matching macro
27           logger.warning("no known macro with `" + buffer + "' prefix");
28         }
29       else if (complete_list.size() == 1)
30         {
31           // good! we have found the macro
32           buffer = new_buffer;
33         }
34       else
35         {
36           // we have more than one matching macro
37           logger.warning("ambiguous prefix `" + buffer + "'");
38           for (std::list<std::string>::const_iterator p = complete_list.begin();
39                p != complete_list.end();
40                p++)
41             {
42               logger.info("Candidate: " + *p);
43             }
44           buffer = new_buffer;
45         }
46
47       displayCursor();
48       return true;
49     }
50   else return false;
51 }