00001 #ifndef LIBSHERPA_LTOKEN_HXX
00002 #define LIBSHERPA_LTOKEN_HXX
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <stdio.h>
00043 #include <libsherpa/EnumSet.hxx>
00044 #include <libsherpa/LexLoc.hxx>
00045
00046 enum TokenFlagValues {
00048 TF_NO_FLAGS = 0,
00049
00051 TF_INSERTED = 0x1u,
00052
00054 TF_BY_PARSER = 0x2u,
00055
00057 TF_AT_FIRST = 0x4u,
00058
00060 TF_REPROCESS = 0x8u,
00061
00063 TF_FIRST_ON_LINE = 0x10u,
00064 };
00065 typedef sherpa::EnumSet<TokenFlagValues> TokenFlags;
00066
00087 namespace sherpa {
00088
00089 struct LToken {
00090 int tokType;
00091 int prevTokType;
00092
00093 TokenFlags flags;
00094
00095 LexLoc loc;
00096 LexLoc endLoc;
00097 std::string str;
00098
00099 char operator[](size_t pos) const
00100 {
00101 return str[pos];
00102 }
00103
00104 LToken()
00105 :loc(), endLoc(), str()
00106 {
00107 tokType = EOF;
00108 prevTokType = EOF;
00109 flags = TF_NO_FLAGS;
00110 }
00111
00112 #if 0
00113 LToken(int tokType, const LexLoc& loc, const std::string& s)
00114 {
00115 this->tokType = tokType;
00116 this->flags = TF_NO_FLAGS;
00117 this->loc = loc;
00118 this->endLoc = LexLoc();
00119 this->str = s;
00120 }
00121 #endif
00122
00123 LToken(int tokType, const LexLoc& loc, const LexLoc& endLoc,
00124 const std::string& s)
00125 {
00126 this->tokType = tokType;
00127 this->prevTokType = prevTokType;
00128 this->flags = TF_NO_FLAGS;
00129 this->loc = loc;
00130 this->endLoc = endLoc;
00131 this->str = s;
00132 }
00133
00134 LToken(int tokType, const LToken& that)
00135 {
00136 this->tokType = that.tokType;
00137 this->prevTokType = that.prevTokType;
00138 this->flags = that.flags;
00139 this->loc = that.loc;
00140 this->endLoc = that.endLoc;
00141 this->str = that.str;
00142 }
00143
00144 LToken(int tokType, const std::string& str)
00145 {
00146 this->tokType = tokType;
00147 this->prevTokType = 0;
00148 this->flags = TF_NO_FLAGS;
00149 this->loc = LexLoc();
00150 this->endLoc = LexLoc();
00151 this->str = str;
00152 }
00153
00154 LToken& operator=(const LToken& that)
00155 {
00156 this->tokType = that.tokType;
00157 this->prevTokType = that.prevTokType;
00158 this->flags = that.flags;
00159 this->loc = that.loc;
00160 this->endLoc = that.endLoc;
00161 this->str = that.str;
00162 return *this;
00163 }
00164
00165 #if 0
00166 bool operator==(const LToken& that)
00167 {
00168 return ((this->tokType == that.tokType) &&
00169 (this->flags == that.flags) &&
00170 (this->loc == that.loc) &&
00171 (this->endLoc == that.endLoc) &&
00172 (this->str == that.str));
00173 }
00174 #endif
00175 };
00176
00177 }
00178
00179 #endif