00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef DeSR_Tokenizer_H
00025 #define DeSR_Tokenizer_H
00026
00027
00028
00029
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <cstdio>
00033 #include <fstream>
00034
00035
00036 #include "Enumerator.h"
00037 #include "Serializable.h"
00038
00039 namespace Parser {
00040
00044 class Scanner : public ptbFlexLexer
00045 {
00046
00047 public:
00048
00050 enum TokenType {
00051 Eof = 0,
00052 Word = 200,
00053 Abbrev,
00054 Date,
00055 Number,
00056 Phone,
00057 Tag,
00058 Url,
00059 Punct
00060 };
00061
00062 static char const* TypeName[];
00063
00067
00068
00069 struct Token {
00070 Token(char const* text = 0, TokenType type = (TokenType)0) :
00071 text(text), type(type) { }
00072
00073 char const* text;
00074 TokenType type;
00075
00076 Token const& operator =(Token const& o) {
00077 if (this != &o) {
00078 delete text;
00079 text = strdup(o.text);
00080 type = o.type;
00081 }
00082 return *this;
00083 }
00084
00085 ~Token() { free((void*)text); }
00086
00087 void serialize(std::ostream& stream);
00088
00089 };
00090
00095 Token scan();
00096 };
00097
00098 #undef YY_DECL
00099 #define YY_DECL Parser::Scanner::Token Parser::Scanner::scan()
00100 #define yylval token.text
00101
00110 class Tokenizer : public Tanl::Enumerator<Scanner::Token const*>
00111 {
00112 public:
00113
00118 Tokenizer(std::istream* is, char const* lang = 0);
00119
00121 Scanner::Token const* Current();
00122
00124 bool MoveNext();
00125
00127 void Reset();
00128
00129 private:
00130 Scanner scanner;
00131 Scanner::Token token;
00132 std::istream& stream;
00133 };
00134
00135 }
00136
00137 #endif // DeSR_Tokenizer_H