00001
00002
00003
00020 #error does anything use this?
00021
00022 namespace mongo {
00023
00024 #if defined(_WIN32)
00025
00026 }
00027
00028 #include <hash_map>
00029 using namespace stdext;
00030
00031 namespace mongo {
00032
00033 typedef const char * MyStr;
00034 struct less_str {
00035 bool operator()(const MyStr & x, const MyStr & y) const {
00036 if ( strcmp(x, y) > 0)
00037 return true;
00038
00039 return false;
00040 }
00041 };
00042
00043 typedef hash_map<const char*, int, hash_compare<const char *, less_str> > strhashmap;
00044
00045 #else
00046
00047 }
00048
00049 #include <ext/hash_map>
00050
00051 namespace mongo {
00052
00053 using namespace __gnu_cxx;
00054
00055 typedef const char * MyStr;
00056 struct eq_str {
00057 bool operator()(const MyStr & x, const MyStr & y) const {
00058 if ( strcmp(x, y) == 0)
00059 return true;
00060
00061 return false;
00062 }
00063 };
00064
00065 typedef hash_map<const char*, int, hash<const char *>, eq_str > strhashmap;
00066
00067 #endif
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 char *p = code;
00079 char last = 0;
00080 while ( *p ) {
00081 if ( starter[*p] ) {
00082 char *q = p+1;
00083 while ( *q && ic[*q] ) q++;
00084 const char *identifier = p;
00085 bool done = *q == 0;
00086 *q = 0;
00087 if ( !reserved.count(identifier) ) {
00088
00089
00090
00091 if ( strcmp(identifier,"obj")==0 && p>code && p[-1] != '.' )
00092 ;
00093 else
00094 vars[identifier] = 1;
00095 }
00096 if ( done )
00097 break;
00098 p = q + 1;
00099 continue;
00100 }
00101
00102 if ( *p == '\'' ) {
00103 p++;
00104 while ( *p && *p != '\'' ) p++;
00105 }
00106 else if ( *p == '"' ) {
00107 p++;
00108 while ( *p && *p != '"' ) p++;
00109 }
00110 p++;
00111 }
00112 }
00113
00114 MiniLex() {
00115 strhashmap atest;
00116 atest["foo"] = 3;
00117 assert( atest.count("bar") == 0 );
00118 assert( atest.count("foo") == 1 );
00119 assert( atest["foo"] == 3 );
00120
00121 for ( int i = 0; i < 256; i++ ) {
00122 ic[i] = starter[i] = false;
00123 }
00124 for ( int i = 'a'; i <= 'z'; i++ )
00125 ic[i] = starter[i] = true;
00126 for ( int i = 'A'; i <= 'Z'; i++ )
00127 ic[i] = starter[i] = true;
00128 for ( int i = '0'; i <= '9'; i++ )
00129 ic[i] = true;
00130 for ( int i = 128; i < 256; i++ )
00131 ic[i] = starter[i] = true;
00132 ic['$'] = starter['$'] = true;
00133 ic['_'] = starter['_'] = true;
00134
00135 reserved["break"] = true;
00136 reserved["case"] = true;
00137 reserved["catch"] = true;
00138 reserved["continue"] = true;
00139 reserved["default"] = true;
00140 reserved["delete"] = true;
00141 reserved["do"] = true;
00142 reserved["else"] = true;
00143 reserved["finally"] = true;
00144 reserved["for"] = true;
00145 reserved["function"] = true;
00146 reserved["if"] = true;
00147 reserved["in"] = true;
00148 reserved["instanceof"] = true;
00149 reserved["new"] = true;
00150 reserved["return"] = true;
00151 reserved["switch"] = true;
00152 reserved["this"] = true;
00153 reserved["throw"] = true;
00154 reserved["try"] = true;
00155 reserved["typeof"] = true;
00156 reserved["var"] = true;
00157 reserved["void"] = true;
00158 reserved["while"] = true;
00159 reserved["with "] = true;
00160 }
00161 };
00162 */
00163
00164 }