libidav/davqlparser.c

Sat, 02 May 2015 18:52:04 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 02 May 2015 18:52:04 +0200
changeset 105
ee0de2b1872e
parent 103
b29692d5f7a7
child 106
9cec78f23cbf
permissions
-rw-r--r--

fixed control flow in int_cmd + committed testcase (enable with #define DO_THE_TEST)

76
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2015 Olaf Wintermann. All rights reserved.
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "davqlparser.h"
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
30 #include <ucx/utils.h>
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
31 #include <string.h>
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
32 #include <stdio.h>
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
33 #include <ctype.h>
76
4c48ce3b9045 structure draft for DavQL statements
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
35 #define sfmtarg(s) ((int)(s).length), (s).ptr
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
36
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
37 // ------------------------------------------------------------------------
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
38 // D E B U G E R
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
39 // ------------------------------------------------------------------------
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
40
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
41 static const char* _map_querytype(davqltype_t type) {
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
42 switch(type) {
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
43 case DAVQL_ERROR: return "ERROR";
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
44 case DAVQL_GET: return "GET";
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
45 case DAVQL_SET: return "SET";
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
46 default: return "unknown";
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
47 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
48 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
49
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
50 static const char* _map_exprtype(davqlexprtype_t type) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
51 switch(type) {
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
52 case DAVQL_UNDEFINED_TYP: return "undefined";
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
53 case DAVQL_NUMBER: return "NUMBER";
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
54 case DAVQL_STRING: return "STRING";
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
55 case DAVQL_TIMESTAMP: return "TIMESTAMP";
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
56 case DAVQL_IDENTIFIER: return "IDENTIFIER";
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
57 case DAVQL_UNARY: return "UNARY";
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
58 case DAVQL_BINARY: return "BINARY";
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
59 case DAVQL_LOGICAL: return "LOGICAL";
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
60 case DAVQL_FUNCCALL: return "FUNCCALL";
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
61 default: return "unknown";
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
62 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
63 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
64
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
65 static const char* _map_specialfield(int info) {
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
66 switch(info) {
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
67 case 0: return "";
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
68 case 1: return "with wildcard";
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
69 case 2: return "(resource data only)";
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
70 default: return "with mysterious identifier";
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
71 }
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
72 }
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
73
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
74 static const char* _map_operator(davqloperator_t op) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
75 // don't use string array, because enum values may change
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
76 switch(op) {
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
77 case DAVQL_NOOP: return "no operator";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
78 case DAVQL_ADD: return "+"; case DAVQL_SUB: return "-";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
79 case DAVQL_MUL: return "*"; case DAVQL_DIV: return "/";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
80 case DAVQL_AND: return "&"; case DAVQL_OR: return "|";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
81 case DAVQL_XOR: return "^"; case DAVQL_NEG: return "~";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
82 case DAVQL_NOT: return "NOT"; case DAVQL_LAND: return "AND";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
83 case DAVQL_LOR: return "OR"; case DAVQL_LXOR: return "XOR";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
84 case DAVQL_EQ: return "="; case DAVQL_NEQ: return "!=";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
85 case DAVQL_LT: return "<"; case DAVQL_GT: return ">";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
86 case DAVQL_LE: return "<="; case DAVQL_GE: return ">=";
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
87 case DAVQL_LIKE: return "LIKE"; case DAVQL_UNLIKE: return "UNLIKE";
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
88 default: return "unknown";
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
89 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
90 }
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
91
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
92 static void dav_debug_ql_fnames_print(DavQLStatement *stmt) {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
93 printf("Field names: ");
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
94 UCX_FOREACH(field, stmt->fields) {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
95 DavQLField *f = field->data;
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
96 printf("%.*s, ", sfmtarg(f->name));
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
97 }
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
98 printf("\b\b \b\b\n");
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
99 }
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
100
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
101 static void dav_debug_ql_stmt_print(DavQLStatement *stmt) {
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
102 // Basic information
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
103 size_t fieldcount = ucx_list_size(stmt->fields);
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
104 int specialfield = 0;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
105 if (stmt->fields) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
106 DavQLField* firstfield = (DavQLField*)stmt->fields->data;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
107 if (firstfield->expr->type == DAVQL_IDENTIFIER) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
108 switch (firstfield->expr->srctext.ptr[0]) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
109 case '*': specialfield = 1; break;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
110 case '-': specialfield = 2; break;
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
111 }
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
112 }
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
113 }
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
114 if (specialfield) {
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
115 fieldcount--;
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
116 }
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
117 printf("Statement: %.*s\nType: %s\nField count: %zu %s\n",
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
118 sfmtarg(stmt->srctext),
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
119 _map_querytype(stmt->type),
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
120 fieldcount,
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
121 _map_specialfield(specialfield));
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
122
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
123 dav_debug_ql_fnames_print(stmt);
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
124 printf("Path: %.*s\nHas where clause: %s\n",
87
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
125 sfmtarg(stmt->path),
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
126 stmt->where ? "yes" : "no");
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
127
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
128 // WITH attributes
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
129 if (stmt->depth == DAV_DEPTH_INFINITY) {
85
0ab1cf261a44 improved grammar + changed depth default, type and added infinity
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
130 printf("Depth: infinity\n");
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
131 } else if (stmt->depth == DAV_DEPTH_PLACEHOLDER) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
132 printf("Depth: placeholder\n");
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
133 } else {
85
0ab1cf261a44 improved grammar + changed depth default, type and added infinity
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
134 printf("Depth: %d\n", stmt->depth);
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
135 }
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
136
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
137 // order by clause
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
138 printf("Order by: ");
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
139 if (stmt->orderby) {
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
140 UCX_FOREACH(crit, stmt->orderby) {
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
141 DavQLOrderCriterion *critdata = crit->data;
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
142 printf("%.*s %s%s", sfmtarg(critdata->column->srctext),
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
143 critdata->descending ? "desc" : "asc",
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
144 crit->next ? ", " : "\n");
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
145 }
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
146 } else {
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
147 printf("nothing\n");
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
148 }
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
149
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
150 // error messages
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
151 if (stmt->errorcode) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
152 printf("\nError code: %d\nError: %s\n",
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
153 stmt->errorcode, stmt->errormessage);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
154 }
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
155 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
156
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
157 static int dav_debug_ql_expr_selected(DavQLExpression *expr) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
158 if (!expr) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
159 printf("Currently no expression selected.\n");
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
160 return 0;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
161 } else {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
162 return 1;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
163 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
164 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
165
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
166 static void dav_debug_ql_expr_print(DavQLExpression *expr) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
167 if (dav_debug_ql_expr_selected(expr)) {
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
168 sstr_t empty = ST("(empty)");
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
169 printf(
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
170 "Text: %.*s\nType: %s\nOperator: %s\n",
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
171 sfmtarg(expr->srctext),
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
172 _map_exprtype(expr->type),
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
173 _map_operator(expr->op));
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
174 if (expr->left || expr->right) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
175 printf("Left hand: %.*s\nRight hand: %.*s\n",
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
176 sfmtarg(expr->left?expr->left->srctext:empty),
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
177 sfmtarg(expr->right?expr->right->srctext:empty));
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
178 }
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
179 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
180 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
181
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
182 #define DQLD_CMD_Q 0
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
183 #define DQLD_CMD_PS 1
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
184 #define DQLD_CMD_PE 2
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
185 #define DQLD_CMD_PF 3
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
186 #define DQLD_CMD_F 10
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
187 #define DQLD_CMD_W 11
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
188 #define DQLD_CMD_O 12
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
189 #define DQLD_CMD_L 21
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
190 #define DQLD_CMD_R 22
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
191 #define DQLD_CMD_N 23
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
192 #define DQLD_CMD_P 24
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
193 #define DQLD_CMD_H 100
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
194
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
195 static int dav_debug_ql_command() {
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
196 printf("> ");
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
197
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
198 char buffer[8];
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
199 fgets(buffer, 8, stdin);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
200 // discard remaining chars
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
201 if (!strchr(buffer, '\n')) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
202 int chr;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
203 while ((chr = fgetc(stdin) != '\n') && chr != EOF);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
204 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
205
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
206 if (!strcmp(buffer, "q\n")) {
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
207 return DQLD_CMD_Q;
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
208 } else if (!strcmp(buffer, "ps\n")) {
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
209 return DQLD_CMD_PS;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
210 } else if (!strcmp(buffer, "pe\n")) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
211 return DQLD_CMD_PE;
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
212 } else if (!strcmp(buffer, "pf\n")) {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
213 return DQLD_CMD_PF;
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
214 } else if (!strcmp(buffer, "l\n")) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
215 return DQLD_CMD_L;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
216 } else if (!strcmp(buffer, "r\n")) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
217 return DQLD_CMD_R;
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
218 } else if (!strcmp(buffer, "h\n")) {
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
219 return DQLD_CMD_H;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
220 } else if (!strcmp(buffer, "f\n")) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
221 return DQLD_CMD_F;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
222 } else if (!strcmp(buffer, "w\n")) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
223 return DQLD_CMD_W;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
224 } else if (!strcmp(buffer, "o\n")) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
225 return DQLD_CMD_O;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
226 } else if (!strcmp(buffer, "n\n")) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
227 return DQLD_CMD_N;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
228 } else if (!strcmp(buffer, "p\n")) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
229 return DQLD_CMD_P;
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
230 } else {
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
231 return -1;
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
232 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
233 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
234
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
235 void dav_debug_statement(DavQLStatement *stmt) {
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
236 if (!stmt) {
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
237 fprintf(stderr, "Debug DavQLStatement failed: null pointer");
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
238 return;
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
239 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
240
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
241 printf("Starting DavQL debugger (type 'h' for help)...\n\n");
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
242 dav_debug_ql_stmt_print(stmt);
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
243
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
244 if (stmt->errorcode) {
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
245 return;
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
246 }
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
247
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
248 DavQLExpression *examineexpr = NULL;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
249 UcxList *examineelem = NULL;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
250 int examineclause = 0;
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
251
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
252 while(1) {
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
253 int cmd = dav_debug_ql_command();
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
254 switch (cmd) {
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
255 case DQLD_CMD_Q: return;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
256 case DQLD_CMD_PS: dav_debug_ql_stmt_print(stmt); break;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
257 case DQLD_CMD_PE: dav_debug_ql_expr_print(examineexpr); break;
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
258 case DQLD_CMD_PF: dav_debug_ql_fnames_print(stmt); break;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
259 case DQLD_CMD_F:
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
260 if (examineclause != DQLD_CMD_F) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
261 examineclause = DQLD_CMD_F;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
262 examineelem = stmt->fields;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
263 examineexpr = stmt->fields ?
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
264 ((DavQLField*)stmt->fields->data)->expr : NULL;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
265 dav_debug_ql_expr_print(examineexpr);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
266 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
267 break;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
268 case DQLD_CMD_W:
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
269 examineclause = 0; examineelem = NULL;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
270 examineexpr = stmt->where;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
271 dav_debug_ql_expr_print(examineexpr);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
272 break;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
273 case DQLD_CMD_O:
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
274 if (examineclause != DQLD_CMD_O) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
275 examineclause = DQLD_CMD_O;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
276 examineelem = stmt->orderby;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
277 examineexpr = stmt->orderby ?
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
278 ((DavQLOrderCriterion*)stmt->orderby->data)->column : NULL;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
279 dav_debug_ql_expr_print(examineexpr);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
280 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
281 break;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
282 case DQLD_CMD_N:
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
283 case DQLD_CMD_P:
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
284 if (examineelem) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
285 UcxList *newelem = (cmd == DQLD_CMD_N ?
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
286 examineelem->next : examineelem->prev);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
287 if (newelem) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
288 examineelem = newelem;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
289 if (examineclause == DQLD_CMD_O) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
290 examineexpr = ((DavQLOrderCriterion*)
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
291 examineelem->data)->column;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
292 } else if (examineclause == DQLD_CMD_F) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
293 examineexpr = ((DavQLField*)examineelem->data)->expr;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
294 } else {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
295 printf("Examining unknown clause type.");
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
296 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
297 dav_debug_ql_expr_print(examineexpr);
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
298 } else {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
299 printf("Reached end of list.\n");
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
300 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
301 } else {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
302 printf("Currently not examining an expression list.\n");
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
303 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
304 break;
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
305 case DQLD_CMD_L:
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
306 if (dav_debug_ql_expr_selected(examineexpr)) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
307 if (examineexpr->left) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
308 examineexpr = examineexpr->left;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
309 dav_debug_ql_expr_print(examineexpr);
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
310 } else {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
311 printf("There is no left subtree.\n");
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
312 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
313 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
314 break;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
315 case DQLD_CMD_R:
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
316 if (dav_debug_ql_expr_selected(examineexpr)) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
317 if (examineexpr->right) {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
318 examineexpr = examineexpr->right;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
319 dav_debug_ql_expr_print(examineexpr);
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
320 } else {
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
321 printf("There is no right subtree.\n");
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
322 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
323 }
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
324 break;
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
325 case DQLD_CMD_H:
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
326 printf(
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
327 "\nCommands:\n"
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
328 "ps: print statement information\n"
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
329 "o: examine order by clause\n"
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
330 "f: examine field list\n"
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
331 "pf: print field names\n"
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
332 "w: examine where clause\n"
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
333 "n: examine next expression "
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
334 "(in order by clause or field list)\n"
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
335 "p: examine previous expression "
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
336 "(in order by clause or field list)\n"
80
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
337 "q: quit\n\n"
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
338 "\nExpression examination:\n"
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
339 "pe: print expression information\n"
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
340 "l: enter left subtree\n"
a2832c054c98 added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents: 79
diff changeset
341 "r: enter right subtree\n");
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
342 break;
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
343 default: printf("unknown command\n");
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
344 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
345 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
346 }
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
347
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
348 // ------------------------------------------------------------------------
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
349 // P A R S E R
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
350 // ------------------------------------------------------------------------
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
351
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
352 #define _unexpected_end_msg "unexpected end of statement"
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
353 #define _invalid_msg "invalid statement"
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
354 #define _unexpected_token "unexpected token (%.*s [->]%.*s %.*s)"
89
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
355 #define _expected_token "expected token '%s' before '%.*s'"
93
2176ffbf1346 added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents: 92
diff changeset
356 #define _expected_by "expected 'by' after 'order' (order [->]%.*s)"
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
357 #define _missing_fmtspec "format specifier missing (%.*s [->]%.*s %.*s)"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
358 #define _invalid_fmtspec "invalid format specifier (%.*s [->]%.*s %.*s)"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
359 #define _unknown_fmtspec "unknown format specifier (%.*s [->]%.*s %.*s)"
88
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
360 #define _missing_quote "missing closing quote symbol (%.*s)"
89
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
361 #define _parser_state "parser reached invalid state"
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
362 #define _unknown_attribute "unknown attribute '%.*s'"
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
363 #define _duplicated_attribute "duplicated attribute '%.*s'"
89
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
364 #define _invalid_depth "invalid depth"
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
365 #define _invalid_path "invalid path"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
366
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
367 #define _identifier_expected "identifier expected (%.*s [->]%.*s %.*s)"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
368 #define _idornum_expected "identifier or number expected (%.*s [->]%.*s %.*s)"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
369 #define _idorstr_expected "identifier or string expected (%.*s [->]%.*s %.*s)"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
370 #define _idorts_expected "identifier or timestamp expected (%.*s [->]%.*s %.*s)"
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
371
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
372 #define token_sstr(listelem) ((sstr_t*)(listelem)->data)
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
373
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
374 static void dav_error_in_context(int errorcode, const char *errormsg,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
375 DavQLStatement *stmt, UcxList *token) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
376 sstr_t emptystring = ST("");
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
377 stmt->errorcode = errorcode;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
378 stmt->errormessage = ucx_sprintf(errormsg,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
379 sfmtarg(token->prev?*token_sstr(token->prev):emptystring),
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
380 sfmtarg(*token_sstr(token)),
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
381 sfmtarg(token->next?*token_sstr(token->next):emptystring)).ptr;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
382 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
383
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
384 // special symbols are single tokens - the % sign MUST NOT be a special symbol
93
2176ffbf1346 added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents: 92
diff changeset
385 static const char *special_token_symbols = ",()+-*/&|^~=!<>";
2176ffbf1346 added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents: 92
diff changeset
386
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
387 static UcxList* dav_parse_tokenize(sstr_t src) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
388 UcxList *tokens = NULL;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
389
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
390 sstr_t *token = NULL;
88
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
391 char insequence = '\0';
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
392 for (size_t i = 0 ; i < src.length ; i++) {
88
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
393 // quoted strings / identifiers are a single token
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
394 if (src.ptr[i] == '\'' || src.ptr[i] == '`') {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
395 if (src.ptr[i] == insequence) {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
396 // add quoted token to list
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
397 token->length++;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
398 tokens = ucx_list_append(tokens, token);
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
399 token = NULL;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
400 insequence = '\0';
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
401 } else if (insequence == '\0') {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
402 insequence = src.ptr[i];
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
403 // always create new token for quoted strings
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
404 if (token) {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
405 tokens = ucx_list_append(tokens, token);
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
406 }
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
407 token = malloc(sizeof(sstr_t));
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
408 token->ptr = src.ptr + i;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
409 token->length = 1;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
410 } else {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
411 // add other kind of quotes to token
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
412 token->length++;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
413 }
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
414 } else if (insequence) {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
415 token->length++;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
416 } else if (isspace(src.ptr[i])) {
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
417 // add token before spaces to list (if any)
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
418 if (token) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
419 tokens = ucx_list_append(tokens, token);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
420 token = NULL;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
421 }
93
2176ffbf1346 added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents: 92
diff changeset
422 } else if (strchr(special_token_symbols, src.ptr[i])) {
2176ffbf1346 added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents: 92
diff changeset
423 // add token before special symbol to list (if any)
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
424 if (token) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
425 tokens = ucx_list_append(tokens, token);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
426 token = NULL;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
427 }
93
2176ffbf1346 added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents: 92
diff changeset
428 // add special symbol as single token to list
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
429 token = malloc(sizeof(sstr_t));
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
430 token->ptr = src.ptr + i;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
431 token->length = 1;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
432 tokens = ucx_list_append(tokens, token);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
433 // set tokenizer ready to read more tokens
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
434 token = NULL;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
435 } else {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
436 // if this is a new token, create memory for it
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
437 if (!token) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
438 token = malloc(sizeof(sstr_t));
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
439 token->ptr = src.ptr + i;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
440 token->length = 0;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
441 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
442 // extend token length when reading more bytes
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
443 token->length++;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
444 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
445 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
446
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
447 if (token) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
448 tokens = ucx_list_append(tokens, token);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
449 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
450
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
451 return tokens;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
452 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
453
88
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
454 static DavQLExpression* dav_parse_expression(
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
455 DavQLStatement* stmt, UcxList* starttoken, size_t n) {
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
456 if (n == 0) {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
457 return NULL;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
458 }
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
459
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
460 DavQLExpression *expr = calloc(1, sizeof(DavQLExpression));
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
461
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
462 // set pointer for source text
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
463 expr->srctext.ptr = token_sstr(starttoken)->ptr;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
464
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
465 // special case - only one token
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
466 if (n == 1) {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
467 expr->srctext.length = token_sstr(starttoken)->length;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
468 char firstchar = expr->srctext.ptr[0];
88
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
469 char lastchar = expr->srctext.ptr[expr->srctext.length-1];
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
470 if (firstchar == '\'') {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
471 expr->type = DAVQL_STRING;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
472 } else if (isdigit(firstchar)) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
473 expr->type = DAVQL_NUMBER;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
474 } else if (firstchar == '%') {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
475 if (expr->srctext.length == 1) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
476 dav_error_in_context(DAVQL_ERROR_MISSING_FMTSPEC,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
477 _missing_fmtspec, stmt, starttoken);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
478 } else if (expr->srctext.length == 2) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
479 switch (expr->srctext.ptr[1]) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
480 case 'd': expr->type = DAVQL_NUMBER; break;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
481 case 's': expr->type = DAVQL_STRING; break;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
482 case 't': expr->type = DAVQL_TIMESTAMP; break;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
483 default:
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
484 dav_error_in_context(DAVQL_ERROR_UNKNOWN_FMTSPEC,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
485 _unknown_fmtspec, stmt, starttoken);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
486 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
487 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
488 dav_error_in_context(DAVQL_ERROR_INVALID_FMTSPEC,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
489 _invalid_fmtspec, stmt, starttoken);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
490 }
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
491 } else {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
492 expr->type = DAVQL_IDENTIFIER;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
493 }
88
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
494 // remove quotes (if any)
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
495 if (firstchar == '\'' || firstchar == '`') {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
496 if (lastchar != firstchar) {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
497 stmt->errorcode = DAVQL_ERROR_MISSING_QUOTE;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
498 stmt->errormessage =
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
499 ucx_sprintf(_missing_quote, sfmtarg(expr->srctext)).ptr;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
500 }
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
501 expr->srctext.ptr++;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
502 if (expr->srctext.length > 2) {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
503 expr->srctext.length -= 2;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
504 } else {
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
505 expr->srctext.length = 0;
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
506 }
4d6b03bd7034 tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents: 87
diff changeset
507 }
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
508 } else {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
509 UcxList* token = starttoken;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
510
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
511 // check, if first token is (
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
512 // if so, verify that last token is ) and throw both away
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
513 if (!sstrcmp(*token_sstr(token), S("("))) {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
514 if (!sstrcmp(*token_sstr(ucx_list_get(token, n-1)), S(")"))) {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
515 token = token->next;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
516 n -= 2;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
517 } else {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
518 // TODO: throw syntax error
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
519 }
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
520 }
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
521
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
522 // process tokens
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
523 for (size_t i = 0 ; i < n ; i++) {
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
524 sstr_t tokendata = *token_sstr(token);
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
525
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
526 // TODO: make it so
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
527
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
528 // go to next token (if this is not the last token)
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
529 if (i < n-1) {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
530 token = token->next;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
531 }
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
532 }
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
533
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
534 // compute length of source text (including delimiters)
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
535 expr->srctext.length = token_sstr(token)->ptr +
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
536 token_sstr(token)->length - expr->srctext.ptr;
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
537 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
538
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
539 return expr;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
540 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
541
87
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
542 static void dav_free_expression(DavQLExpression *expr) {
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
543 if (expr->left) {
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
544 dav_free_expression(expr->left);
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
545 }
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
546 if (expr->right) {
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
547 dav_free_expression(expr->right);
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
548 }
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
549 free(expr);
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
550 }
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
551
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
552 #define _step_fieldlist_ 10 // field list
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
553 #define _step_FROM_ 20 // FROM clause
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
554 #define _step_WITH_ 30 // WITH clause
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
555 #define _step_WITHopt_ 530 // expecting more WITH details or end
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
556 #define _step_WHERE_ 40 // WHERE clause
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
557 #define _step_ORDER_BY_ 50 // ORDER BY clause
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
558 #define _step_ORDER_BYopt_ 550 // expecting more ORDER BY details or end
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
559 #define _step_end_ 500 // expect end
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
560
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
561 struct fieldlist_parser_state {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
562 UcxList *expr_firsttoken;
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
563 DavQLField *currentfield;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
564 size_t expr_len;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
565 /*
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
566 * 0: begin of field list - may encounter "*" or "-" special fields
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
567 * 1: collect expression token
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
568 * switch to step 2 on keyword "as"
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
569 * expect "," or "from" only if expr_len is 1 (add to list and continue)
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
570 * 2: expect one token (identifier) for as clause
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
571 * 3: expect a ",": continue with step 1
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
572 * or a "from": leave field list parser
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
573 * 4: expect end of field list (i.e. a "from" keyword)
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
574 */
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
575 int step;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
576 };
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
577
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
578 static void dav_free_field(DavQLField *field) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
579 dav_free_expression(field->expr);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
580 free(field);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
581 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
582
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
583 static int dav_parse_fieldlist(DavQLStatement *stmt, UcxList *token,
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
584 struct fieldlist_parser_state *state) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
585 sstr_t tokendata = *token_sstr(token);
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
586
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
587 _Bool fromkeyword = !sstrcasecmp(tokendata, S("from"));
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
588 _Bool comma = !sstrcmp(tokendata, S(","));
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
589
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
590 switch (state->step) {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
591 case 0:
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
592 if (!sstrcmp(tokendata, S("*")) || !sstrcmp(tokendata, S("-"))) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
593 DavQLField *field = malloc(sizeof(DavQLField));
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
594 field->name = tokendata;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
595 field->expr = calloc(1, sizeof(DavQLExpression));
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
596 field->expr->type = DAVQL_IDENTIFIER;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
597 field->expr->srctext = tokendata;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
598 stmt->fields = ucx_list_append(stmt->fields, field);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
599
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
600 if (tokendata.ptr[0] == '-') {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
601 // no further fields may follow, if dash symbol has been found
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
602 state->step = 4;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
603 } else {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
604 state->step = 3;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
605 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
606 return _step_fieldlist_;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
607 }
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
608 // did not encounter special field, fall through to step 1
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
609 state->step = 1;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
610 case 1:
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
611 if (fromkeyword || comma) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
612 // add possible identifier to list
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
613 if (state->expr_firsttoken) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
614 // TODO: skip comma in function call)
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
615 if (state->expr_len > 1) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
616 stmt->errorcode = DAVQL_ERROR_UNEXPECTED_TOKEN;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
617 stmt->errormessage = ucx_sprintf(_expected_token,
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
618 "AS", sfmtarg(tokendata)).ptr;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
619 return 0;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
620 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
621
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
622 DavQLExpression *expr = dav_parse_expression(
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
623 stmt, state->expr_firsttoken, state->expr_len);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
624
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
625 if (expr->type != DAVQL_IDENTIFIER) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
626 dav_free_expression(expr);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
627 stmt->errorcode = DAVQL_ERROR_UNEXPECTED_TOKEN;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
628 stmt->errormessage = ucx_sprintf(_expected_token,
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
629 "AS", sfmtarg(tokendata)).ptr;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
630 return 0;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
631 } // TODO: do not allow identifier when wildcard is present
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
632
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
633 DavQLField *field = malloc(sizeof(DavQLField));
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
634 field->expr = expr;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
635 field->name = field->expr->srctext;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
636 stmt->fields = ucx_list_append(stmt->fields, field);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
637
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
638 state->expr_firsttoken = NULL;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
639 state->expr_len = 0;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
640
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
641 if (fromkeyword) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
642 return _step_FROM_;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
643 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
644 } else {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
645 dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN,
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
646 _unexpected_token, stmt, token);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
647 return 0;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
648 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
649 } else if (!sstrcasecmp(tokendata, S("as"))) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
650 // TODO: return error, if expr_first_token is NULL
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
651 state->currentfield = malloc(sizeof(DavQLField));
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
652 state->currentfield->expr = dav_parse_expression(
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
653 stmt, state->expr_firsttoken, state->expr_len);
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
654
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
655 state->expr_firsttoken = NULL;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
656 state->expr_len = 0;
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
657
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
658 state->step = 2;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
659 } else {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
660 // collect tokens for field expression
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
661 if (state->expr_firsttoken) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
662 state->expr_len++;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
663 } else {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
664 state->expr_firsttoken = token;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
665 state->expr_len = 1;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
666 }
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
667 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
668
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
669 return _step_fieldlist_;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
670 case 2: {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
671 DavQLExpression *expr = dav_parse_expression(stmt, token, 1);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
672 if (expr->type == DAVQL_IDENTIFIER) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
673 state->currentfield->name = expr->srctext;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
674 stmt->fields = ucx_list_append(stmt->fields, state->currentfield);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
675 state->currentfield = NULL;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
676 } else {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
677 dav_free_field(state->currentfield);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
678 dav_error_in_context(DAVQL_ERROR_IDENTIFIER_EXPECTED,
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
679 _identifier_expected, stmt, token);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
680
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
681 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
682 dav_free_expression(expr);
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
683 state->step = 3;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
684
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
685 return _step_fieldlist_;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
686 }
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
687 case 3:
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
688 if (fromkeyword) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
689 return _step_FROM_;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
690 } else if (comma) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
691 state->step = 1;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
692 return _step_fieldlist_;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
693 } else {
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
694 dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN,
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
695 _unexpected_token, stmt, token);
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
696 return 0;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
697 }
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
698 case 4:
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
699 if (fromkeyword) {
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
700 return _step_FROM_;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
701 } else {
99
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
702 stmt->errorcode = DAVQL_ERROR_UNEXPECTED_TOKEN;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
703 stmt->errormessage = ucx_sprintf(_expected_token,
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
704 "FROM", sfmtarg(tokendata)).ptr;
579238097973 fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents: 98
diff changeset
705 return 0;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
706 }
103
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
707 default:
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
708 stmt->errorcode = DAVQL_ERROR_INVALID;
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
709 stmt->errormessage = strdup(_parser_state);
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
710 return 0;
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
711 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
712 }
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
713
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
714 static int dav_parse_from(DavQLStatement *stmt, UcxList *token) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
715 sstr_t tokendata = *token_sstr(token);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
716
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
717 if (!sstrcasecmp(tokendata, S("with"))) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
718 return _step_WITH_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
719 } else if (!sstrcasecmp(tokendata, S("where"))) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
720 return _step_WHERE_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
721 } else if (!sstrcasecmp(tokendata, S("order"))) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
722 return _step_ORDER_BY_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
723 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
724 if (stmt->path.ptr) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
725 if (stmt->path.ptr[0] == '/') {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
726 char *end = tokendata.ptr+tokendata.length;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
727 stmt->path.length = end - stmt->path.ptr;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
728 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
729 stmt->errorcode = DAVQL_ERROR_INVALID_PATH;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
730 stmt->errormessage = strdup(_invalid_path);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
731 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
732 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
733 if (tokendata.ptr[0] == '/' || !sstrcmp(tokendata, S("%s"))) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
734 stmt->path = tokendata;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
735 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
736 stmt->errorcode = DAVQL_ERROR_INVALID_PATH;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
737 stmt->errormessage = strdup(_invalid_path);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
738 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
739 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
740 return _step_FROM_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
741 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
742 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
743
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
744 struct with_parser_state {
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
745 /*
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
746 * 0: key
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
747 * 1: =
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
748 * 2: value
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
749 * 3: comma or new clause or end
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
750 */
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
751 int step;
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
752 /*
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
753 * 1: depth
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
754 */
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
755 int key;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
756 int keymask;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
757 };
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
758
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
759 static int dav_parse_with_clause(DavQLStatement *stmt, UcxList *token,
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
760 struct with_parser_state *state) {
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
761 sstr_t tokendata = *token_sstr(token);
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
762
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
763 switch (state->step) {
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
764 case 0:
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
765 if (!sstrcasecmp(tokendata, S("depth"))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
766 state->key = 1;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
767 state->step = 1;
103
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
768 if (state->keymask & state->key) {
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
769 stmt->errorcode = DAVQL_ERROR_DUPLICATED_ATTRIBUTE;
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
770 stmt->errormessage = ucx_sprintf(_duplicated_attribute,
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
771 sfmtarg(tokendata)).ptr;
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
772 } else {
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
773 state->keymask |= state->key;
b29692d5f7a7 added clang config + fixed control flow in two parser functions
Mike Becker <universe@uap-core.de>
parents: 102
diff changeset
774 }
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
775 } else {
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
776 stmt->errorcode = DAVQL_ERROR_UNKNOWN_ATTRIBUTE;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
777 stmt->errormessage = ucx_sprintf(_unknown_attribute,
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
778 sfmtarg(tokendata)).ptr;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
779 }
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
780 return _step_WITH_; // continue parsing WITH clause
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
781 case 1:
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
782 if (sstrcmp(tokendata, S("="))) {
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
783 stmt->errorcode = DAVQL_ERROR_UNEXPECTED_TOKEN;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
784 stmt->errormessage = ucx_sprintf(_expected_token,
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
785 "=", sfmtarg(tokendata)).ptr;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
786 } else {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
787 state->step = 2;
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
788 }
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
789 return _step_WITH_; // continue parsing WITH clause
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
790 case 2:
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
791 switch (state->key) {
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
792 case 1: /* depth */
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
793 if (!sstrcasecmp(tokendata, S("infinity"))) {
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
794 stmt->depth = DAV_DEPTH_INFINITY;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
795 } else {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
796 DavQLExpression *depthexpr =
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
797 dav_parse_expression(stmt, token, 1);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
798
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
799 if (depthexpr->type == DAVQL_NUMBER) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
800 if (depthexpr->srctext.ptr[0] == '%') {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
801 stmt->depth = DAV_DEPTH_PLACEHOLDER;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
802 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
803 sstr_t depthstr = depthexpr->srctext;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
804 char *conv = malloc(depthstr.length+1);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
805 char *chk;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
806 memcpy(conv, depthstr.ptr, depthstr.length);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
807 conv[depthstr.length] = '\0';
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
808 stmt->depth = strtol(conv, &chk, 10);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
809 if (*chk || stmt->depth < -1) {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
810 stmt->errorcode = DAVQL_ERROR_INVALID_DEPTH;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
811 stmt->errormessage = strdup(_invalid_depth);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
812 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
813 free(conv);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
814 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
815 } else {
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
816 stmt->errorcode = DAVQL_ERROR_INVALID_DEPTH;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
817 stmt->errormessage = strdup(_invalid_depth);
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
818 }
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
819
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
820 dav_free_expression(depthexpr);
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
821 }
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
822 break;
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
823 }
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
824 state->step = 3;
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
825 return _step_WITHopt_; // continue parsing WITH clause
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
826 case 3:
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
827 // a with clause may be continued with a comma
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
828 // or another clause may follow
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
829 if (!sstrcmp(tokendata, S(","))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
830 state->step = 0; // reset clause parser
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
831 return _step_WITH_;
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
832 } else if (!sstrcasecmp(tokendata, S("where"))) {
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
833 return _step_WHERE_;
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
834 } else if (!sstrcasecmp(tokendata, S("order"))) {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
835 return _step_ORDER_BY_;
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
836 } else {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
837 dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
838 _unexpected_token, stmt, token);
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
839 return 0;
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
840 }
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
841 default:
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
842 stmt->errorcode = DAVQL_ERROR_INVALID;
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
843 stmt->errormessage = strdup(_parser_state);
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
844 return 0;
90
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
845 }
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
846 }
46971430650b parser for with-clause ready to parse more attributes, but marks duplicated attributes as error
Mike Becker <universe@uap-core.de>
parents: 89
diff changeset
847
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
848 struct orderby_parser_state {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
849 /*
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
850 * 0: expect by keyword
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
851 * 1: expect identifier / number
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
852 * 2: expect asc / desc or comma
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
853 * 3: expect comma
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
854 */
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
855 int step;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
856 DavQLOrderCriterion *crit;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
857 };
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
858
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
859 static int dav_parse_orderby_clause(DavQLStatement *stmt, UcxList *token,
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
860 struct orderby_parser_state *state) {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
861
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
862 sstr_t tokendata = *token_sstr(token);
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
863
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
864 switch (state->step) {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
865 case 0:
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
866 if (!sstrcasecmp(tokendata, S("by"))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
867 state->step++;
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
868 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
869 stmt->errorcode = DAVQL_ERROR_UNEXPECTED_TOKEN;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
870 stmt->errormessage = ucx_sprintf(_expected_by,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
871 sfmtarg(tokendata)).ptr;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
872 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
873 return _step_ORDER_BY_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
874 case 1:
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
875 state->crit = malloc(sizeof(DavQLOrderCriterion));
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
876 state->crit->column = dav_parse_expression(stmt, token, 1);
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
877 state->crit->descending = 0;
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
878
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
879 if (!state->crit->column || (
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
880 state->crit->column->type != DAVQL_NUMBER &&
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
881 state->crit->column->type != DAVQL_IDENTIFIER)) {
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
882 free(state->crit);
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
883 dav_error_in_context(DAVQL_ERROR_IDORNUM_EXPECTED,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
884 _idornum_expected, stmt, token);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
885 } else {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
886 stmt->orderby = ucx_list_append(stmt->orderby, state->crit);
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
887 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
888
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
889 // continue parsing clause, if more tokens available
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
890 state->step++;
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
891 return _step_ORDER_BYopt_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
892 case 2:
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
893 if (!sstrcasecmp(tokendata, S("desc"))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
894 state->crit->descending = 1;
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
895 } else if (!sstrcasecmp(tokendata, S("asc"))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
896 state->crit->descending = 0;
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
897 } else if (!sstrcmp(tokendata, S(","))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
898 state->step = 1; // reset clause parser
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
899 return _step_ORDER_BY_; // statement must not end now
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
900 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
901 dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
902 _unexpected_token, stmt, token);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
903 return 0;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
904 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
905 // continue parsing clause, if more tokens available
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
906 state++;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
907 return _step_ORDER_BYopt_;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
908 case 3:
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
909 if (!sstrcmp(tokendata, S(","))) {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
910 state->step = 1; // reset clause parser
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
911 return _step_ORDER_BY_; // statement must not end now
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
912 } else {
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
913 dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
914 _unexpected_token, stmt, token);
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
915 return 0;
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
916 }
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
917 }
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
918
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
919 return _step_end_;
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
920 }
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
921
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
922 static void dav_free_order_criterion(DavQLOrderCriterion *crit) {
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
923 if (crit->column) { // do it null-safe though column is expected to be set
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
924 dav_free_expression(crit->column);
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
925 }
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
926 free(crit);
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
927 }
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
928
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
929 /**
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
930 * Semantic analysis of a get statement.
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
931 * @param stmt the statement to analyze.
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
932 */
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
933 static void dav_analyze_get_statement(DavQLStatement *stmt) {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
934 // TODO: make it so
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
935 }
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
936
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
937
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
938 /**
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
939 * Parser of a get statement.
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
940 * @param stmt the statement object that shall contain the syntax tree
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
941 * @param tokens the token list
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
942 */
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
943 static void dav_parse_get_statement(DavQLStatement *stmt, UcxList *tokens) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
944 stmt->type = DAVQL_GET;
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
945
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
946 int step = _step_fieldlist_;
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
947
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
948 struct with_parser_state state_with;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
949 memset(&state_with, 0, sizeof(struct with_parser_state));
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
950 struct orderby_parser_state state_orderby;
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
951 memset(&state_orderby, 0, sizeof(struct orderby_parser_state));
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
952 struct fieldlist_parser_state state_fieldlist;
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
953 memset(&state_fieldlist, 0, sizeof(struct fieldlist_parser_state));
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
954
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
955 // Process tokens
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
956 UCX_FOREACH(token, tokens) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
957 switch (step) {
89
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
958 // too much input data
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
959 case _step_end_:
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
960 dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN,
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
961 _unexpected_token, stmt, token);
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
962 break;
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
963 // field list
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
964 case _step_fieldlist_: {
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
965 step = dav_parse_fieldlist(stmt, token, &state_fieldlist);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
966 break;
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
967 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
968 // from clause
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
969 case _step_FROM_: {
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
970 step = dav_parse_from(stmt, token);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
971 break;
87
ed21d95984bb removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents: 86
diff changeset
972 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
973 // with clause
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
974 case _step_WITH_:
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
975 case _step_WITHopt_: {
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
976 step = dav_parse_with_clause(stmt, token, &state_with);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
977 break;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
978 }
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
979 // where clause
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
980 case _step_WHERE_:
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
981 // TODO: implement
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
982 step = _step_end_;
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
983 break;
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
984 // order by clause
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
985 case _step_ORDER_BY_:
96
896022673e0e special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents: 95
diff changeset
986 case _step_ORDER_BYopt_:
97
f82cb65a78ec fixed static variable fail
Mike Becker <universe@uap-core.de>
parents: 96
diff changeset
987 step = dav_parse_orderby_clause(stmt, token, &state_orderby);
92
e073cf4afc6a added order by clause to grammar + moved with clause right after the from clause
Mike Becker <universe@uap-core.de>
parents: 91
diff changeset
988 break;
89
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
989 default:
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
990 stmt->errorcode = DAVQL_ERROR_INVALID;
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
991 stmt->errormessage = strdup(_parser_state);
785f6007a0c1 parser for with clause + unexpected token message, if something is beyond the with clause
Mike Becker <universe@uap-core.de>
parents: 88
diff changeset
992 }
94
8822f7c08843 removed ultrabreak gotos
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
993
8822f7c08843 removed ultrabreak gotos
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
994 // cancel processing, when an error has been detected
8822f7c08843 removed ultrabreak gotos
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
995 if (stmt->errorcode) {
8822f7c08843 removed ultrabreak gotos
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
996 break;
8822f7c08843 removed ultrabreak gotos
Mike Becker <universe@uap-core.de>
parents: 93
diff changeset
997 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
998 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
999
102
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1000 if (!stmt->errorcode) {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1001 if (step < _step_end_) {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1002 stmt->errorcode = DAVQL_ERROR_UNEXPECTED_END;
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1003 stmt->errormessage = strdup(_unexpected_end_msg);
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1004 } else {
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1005 dav_analyze_get_statement(stmt);
e9ae1318a559 reworked expression grammar (removed left recursion) + added field names to debugger + fixed bug when WITH-clause was the last clause in a statement
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
1006 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1007 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1008 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1009
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1010 static void dav_parse_set_statement(DavQLStatement *stmt, UcxList *tokens) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1011 stmt->type = DAVQL_SET;
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1012
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1013 UCX_FOREACH(token, tokens) {
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1014 sstr_t tokendata = *token_sstr(token);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1015
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1016 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1017 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1018
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1019 DavQLStatement* dav_parse_statement(sstr_t srctext) {
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1020 DavQLStatement *stmt = calloc(1, sizeof(DavQLStatement));
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1021
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1022 // default values
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1023 stmt->type = -1;
85
0ab1cf261a44 improved grammar + changed depth default, type and added infinity
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
1024 stmt->depth = 1;
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1025
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1026 // save trimmed source text
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1027 stmt->srctext = sstrtrim(srctext);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1028
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1029 // tokenization
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1030 UcxList* tokens = dav_parse_tokenize(stmt->srctext);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1031
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1032 if (tokens) {
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1033 // use first token to determine query type
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1034 sstr_t token = *token_sstr(tokens);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1035 free(tokens->data);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1036 tokens = ucx_list_remove(tokens, tokens);
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1037
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1038 if (!sstrcasecmp(token, S("get"))) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1039 dav_parse_get_statement(stmt, tokens);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1040 } else if (!sstrcasecmp(token, S("set"))) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1041 dav_parse_set_statement(stmt, tokens);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1042 } else {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1043 stmt->type = DAVQL_ERROR;
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1044 stmt->errorcode = DAVQL_ERROR_INVALID;
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1045 stmt->errormessage = strdup(_invalid_msg);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1046 }
83
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1047
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1048 // free token data
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1049 UCX_FOREACH(token, tokens) {
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1050 free(token->data);
7d20ce5d235b improved expression parser (can now detect literals and identifiers) - TODO: tokenizer must not split strings and "backstick-identifiers"
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
1051 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1052 ucx_list_free(tokens);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1053 } else {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1054 stmt->type = DAVQL_ERROR;
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1055 stmt->errorcode = DAVQL_ERROR_INVALID;
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1056 stmt->errormessage = strdup(_invalid_msg);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1057 }
79
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1058
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1059 return stmt;
59c518ae0641 added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents: 76
diff changeset
1060 }
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1061
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1062 void dav_free_statement(DavQLStatement *stmt) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1063 UCX_FOREACH(expr, stmt->fields) {
98
237844f263b4 minor grammar fix (alias name is now identifier and not string) + completed debugger (so far) + separated field list parser (currently unable to parse alias names) + new structure for fields
Mike Becker <universe@uap-core.de>
parents: 97
diff changeset
1064 dav_free_field(expr->data);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1065 }
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1066 ucx_list_free(stmt->fields);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1067
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1068 if (stmt->where) {
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1069 dav_free_expression(stmt->where);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1070 }
86
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1071 if (stmt->errormessage) {
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1072 free(stmt->errormessage);
ecba8bdf9741 davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents: 85
diff changeset
1073 }
95
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
1074 UCX_FOREACH(crit, stmt->orderby) {
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
1075 dav_free_order_criterion(crit->data);
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
1076 }
8ed7d8df6427 simplified with clause parsing + added order by to data structure and debugger (TODO: implement)
Mike Becker <universe@uap-core.de>
parents: 94
diff changeset
1077 ucx_list_free(stmt->orderby);
82
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1078 free(stmt);
0567444f2d76 renamed some enums to avoid collisions with macros + minor grammar change (backsticks for identifiers) + tokenizer + parser skeleton
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
1079 }

mercurial