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 #ifndef yyFlexLexer
00028
00029 # define yyFlexLexer ptbFlexLexer
00030 # include "FlexLexer.h"
00031 #endif
00032
00033
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <cstdio>
00037 #include <fstream>
00038
00039
00040 #include "Enumerator.h"
00041 #include "Serializable.h"
00042
00043 namespace Parser {
00044
00045 class Scanner : public yyFlexLexer
00046 {
00047
00048 public:
00049
00051 enum TokenType {
00052 Eof = 0,
00053 Word = 200,
00054 Abbrev,
00055 Date,
00056 Number,
00057 Phone,
00058 Tag,
00059 Url,
00060 Punct
00061 };
00062
00063 static char const* TypeName[];
00064
00068
00069
00070 struct Token {
00071 Token(char const* text = 0, TokenType type = (TokenType)0) :
00072 text(text), type(type) { }
00073
00074 char const* text;
00075 TokenType type;
00076
00077 Token const& operator =(Token const& o) {
00078 if (this != &o) {
00079 delete text;
00080 text = strdup(o.text);
00081 type = o.type;
00082 }
00083 return *this;
00084 }
00085
00086 ~Token() { free((void*)text); }
00087
00088 void serialize(std::ostream& stream);
00089
00090 };
00091
00096 Token scan();
00097 };
00098
00099 #undef YY_DECL
00100 #define YY_DECL Parser::Scanner::Token Parser::Scanner::scan()
00101 #define yylval token.text
00102
00109 class Tokenizer : public Tanl::Enumerator<Scanner::Token const*>
00110 {
00111 public:
00112
00117 Tokenizer(std::istream* is, char const* lang = 0);
00118
00120 Scanner::Token const* Current();
00121
00123 bool MoveNext();
00124
00126 void Reset();
00127
00128 private:
00129 Scanner scanner;
00130 Scanner::Token token;
00131 std::istream& stream;
00132 };
00133
00134 }
00135
00136 #endif // DeSR_Tokenizer_H