X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FTLexerPush.cc;fp=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FTLexerPush.cc;h=6b2acae7c4b6be1e3ebe02b7424a326cd50e1c99;hb=30060cffed61b88fe53e4d6386b606050d6dfda0;hp=0000000000000000000000000000000000000000;hpb=e6927665462cbbace76cff1b17d4f8badcb44eda;p=helm.git diff --git a/helm/DEVEL/mathml_editor/src/TLexerPush.cc b/helm/DEVEL/mathml_editor/src/TLexerPush.cc new file mode 100644 index 000000000..6b2acae7c --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/TLexerPush.cc @@ -0,0 +1,82 @@ + +#include "TLexerPush.hh" + +TLexerPush::TLexerPush() +{ + state = ACCEPT; +} + +TToken +TLexerPush::pop() +{ + if (tokens.empty()) throw EmptyBuffer(); + else + { + TToken res = tokens.front(); + tokens.pop_front(); + if (tokens.size() == 1 && state == CONTROL) state = ACCEPT; + return res; + } +} + +TToken +TLexerPush::front() const +{ + if (tokens.empty()) throw EmptyBuffer(); + else return tokens.front(); +} + +bool +TLexerPush::empty() const +{ + return tokens.empty(); +} + +bool +TLexerPush::pending() const +{ + return state == ESCAPE; +} + +bool +TLexerPush::ambiguous() const +{ + return tokens.size() == 1 && state == CONTROL; +} + +void +TLexerPush::push(TChar ch) +{ + switch (state) + { + case ACCEPT: + if (ch == '\\') state = ESCAPE; + else tokens.push_back(TToken(ch)); + break; + case ESCAPE: + tokens.push_back(TToken(TToken::CONTROL, std::string(1, ch))); + if (isUnicodeAlpha(ch)) state = CONTROL; + else state = ACCEPT; + break; + case CONTROL: + if (ch == '\\') state = ESCAPE; + else if (isUnicodeAlpha(ch)) + { + assert(!tokens.empty()); + TToken& tok = tokens.back(); + tok.value.push_back(ch); + } + else if (isUnicodeSpace(ch)) state = IGNORE_SPACE; + else + { + tokens.push_back(TToken(ch)); + state = ACCEPT; + } + break; + case IGNORE_SPACE: + if (ch == '\\') state = ESCAPE; + else if (isUnicodeSpace(ch)) ; + else tokens.push_back(TToken(ch)); + break; + } +}