added special symbol list to tokenizer

Mon, 13 Apr 2015 20:06:04 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 13 Apr 2015 20:06:04 +0200
changeset 93
2176ffbf1346
parent 92
e073cf4afc6a
child 94
8822f7c08843

added special symbol list to tokenizer

libidav/davqlparser.c file | annotate | diff | comparison | revisions
--- a/libidav/davqlparser.c	Mon Apr 13 19:04:46 2015 +0200
+++ b/libidav/davqlparser.c	Mon Apr 13 20:06:04 2015 +0200
@@ -246,7 +246,7 @@
 #define _invalid_msg "invalid statement"
 #define _unexpected_token "unexpected token (%.*s [->]%.*s %.*s)"
 #define _expected_token "expected token '%s' before '%.*s'"
-#define _expected_by "expected by after order (order [->]%.*s)"
+#define _expected_by "expected 'by' after 'order' (order [->]%.*s)"
 #define _missing_quote "missing closing quote symbol (%.*s)"
 #define _parser_state "parser reached invalid state"
 #define _unknown_attribute "unknown attribute '%.*s'"
@@ -254,10 +254,11 @@
 #define _invalid_depth "invalid depth"
 #define _identifier_expected "identifier expected, but found: %.*s"
 
+static const char *special_token_symbols = ",()+-*/&|^~=!<>";
+
 static UcxList* dav_parse_tokenize(sstr_t src) {
     UcxList *tokens = NULL;
     
-    // Delimiters: whitespace and dead whitespace around commas
     sstr_t *token = NULL;
     char insequence = '\0';
     for (size_t i = 0 ; i < src.length ; i++) {
@@ -290,13 +291,13 @@
                 tokens = ucx_list_append(tokens, token);
                 token = NULL;
             }
-        } else if (src.ptr[i] == ',') {
-            // add token before comma to list (if any)
+        } else if (strchr(special_token_symbols, src.ptr[i])) {
+            // add token before special symbol to list (if any)
             if (token) {
                 tokens = ucx_list_append(tokens, token);
                 token = NULL;
             }
-            // add comma as token to list
+            // add special symbol as single token to list
             token = malloc(sizeof(sstr_t));
             token->ptr = src.ptr + i;
             token->length = 1;
@@ -571,7 +572,8 @@
                     exprstart = NULL;
                     exprlen = 0;
                 } else {
-                    // TODO: throw syntax error
+                    dav_parse_unexpected_token(stmt, token);
+                    goto ultrabreak;
                 }
                 
                 if (fromkeyword) {

mercurial