libidav/davqlparser.c

changeset 263
f24b730cb75e
parent 185
cd42cccee550
child 288
cd3846cc8b25
equal deleted inserted replaced
262:e2579b63595a 263:f24b730cb75e
473 // determine token class (order of if-statements is very important!) 473 // determine token class (order of if-statements is very important!)
474 char firstchar = token->value.ptr[0]; 474 char firstchar = token->value.ptr[0];
475 475
476 if (isdigit(firstchar)) { 476 if (isdigit(firstchar)) {
477 token->tokenclass = DAVQL_TOKEN_NUMBER; 477 token->tokenclass = DAVQL_TOKEN_NUMBER;
478 // check, if all characters are digits
479 for (size_t i = 1 ; i < token->value.length ; i++) {
480 if (!isdigit(token->value.ptr[i])) {
481 token->tokenclass = DAVQL_TOKEN_INVALID;
482 break;
483 }
484 }
478 } else if (firstchar == '%') { 485 } else if (firstchar == '%') {
479 token->tokenclass = DAVQL_TOKEN_FMTSPEC; 486 token->tokenclass = DAVQL_TOKEN_FMTSPEC;
480 } else if (token->value.length == 1) { 487 } else if (token->value.length == 1) {
481 switch (firstchar) { 488 switch (firstchar) {
482 case '(': token->tokenclass = DAVQL_TOKEN_OPENP; break; 489 case '(': token->tokenclass = DAVQL_TOKEN_OPENP; break;
494 token->tokenclass = DAVQL_TOKEN_IDENTIFIER; 501 token->tokenclass = DAVQL_TOKEN_IDENTIFIER;
495 } else if (iskeyword(token)) { 502 } else if (iskeyword(token)) {
496 token->tokenclass = DAVQL_TOKEN_KEYWORD; 503 token->tokenclass = DAVQL_TOKEN_KEYWORD;
497 } else { 504 } else {
498 token->tokenclass = DAVQL_TOKEN_IDENTIFIER; 505 token->tokenclass = DAVQL_TOKEN_IDENTIFIER;
506 // TODO: check for illegal characters
499 } 507 }
500 508
501 // remove quotes (extreme cool feature) 509 // remove quotes (extreme cool feature)
502 if (token->tokenclass == DAVQL_TOKEN_STRING || 510 if (token->tokenclass == DAVQL_TOKEN_STRING ||
503 (token->tokenclass == DAVQL_TOKEN_IDENTIFIER && firstchar == '`')) { 511 (token->tokenclass == DAVQL_TOKEN_IDENTIFIER && firstchar == '`')) {

mercurial