53 static const struct keyword keywords[] = {
104 {
"PROJECT", PROJECT},
105 {
"MAXHEAP", MAXHEAP},
106 {
"MEMHASH", MEMHASH},
108 {
"RELATION", RELATION},
110 {
"ATTRIBUTE", ATTRIBUTE}
114 static const int8_t skip_hint[] = {0, 13, 21, 27, 33, 36, 44, 47, 48};
116 static char separators[] =
"#.;,() \t\n";
119 lexer_start(lexer_t *lexer,
char *input, token_t *token, value_t *value)
121 lexer->input = input;
122 lexer->prev_pos = input;
123 lexer->token = token;
124 lexer->value = value;
130 get_token_id(
const char *
string,
const size_t length)
135 if(
sizeof(skip_hint) < length || length < 1) {
140 start = skip_hint[length - 1];
141 if(
sizeof(skip_hint) == length) {
142 end =
sizeof(keywords) /
sizeof(keywords[0]);
144 end = skip_hint[length];
147 for(i = start; i < end; i++) {
148 if(strncasecmp(keywords[i].
string,
string, length) == 0) {
149 return keywords[i].token;
157 next_real(lexer_t *lexer,
const char *s)
161 #if DB_FEATURE_FLOATS
166 long_value = strtol(s, &end, 10);
168 #if DB_FEATURE_FLOATS
171 float_value = strtof(s, &end);
172 if(float_value == 0 && s == end) {
175 memcpy(lexer->value, &float_value,
sizeof(float_value));
176 *lexer->token = FLOAT_VALUE;
184 if(long_value == 0 && errno != 0) {
187 memcpy(lexer->value, &long_value,
sizeof(long_value));
188 *lexer->token = INTEGER_VALUE;
195 next_string(lexer_t *lexer,
const char *s)
200 end = strchr(s,
'\'');
206 *lexer->token = STRING_VALUE;
207 lexer->input = end + 1;
209 memcpy(lexer->value, s, length);
210 (*lexer->value)[length] =
'\0';
216 next_token(lexer_t *lexer,
const char *s)
220 length = strcspn(s, separators);
227 *lexer->token = get_token_id(s, length);
228 lexer->input = s + length;
229 if(*lexer->token != NONE) {
236 *lexer->token = IDENTIFIER;
238 memcpy(lexer->value, s, length);
239 (*lexer->value)[length] =
'\0';
245 lexer_next(lexer_t *lexer)
249 *lexer->token = NONE;
251 s += strspn(s,
" \t\n");
257 return next_string(lexer, s + 1);
261 if(isdigit((
int)*s) || (*s ==
'-' && isdigit((
int)s[1]))) {
262 return next_real(lexer, s);
266 return next_token(lexer, s);
271 lexer_rewind(lexer_t *lexer)
273 lexer->input = lexer->prev_pos;
Definitions and declarations for AQL, the Antelope Query Language.
#define NULL
The null pointer.