Sat, 25 Aug 2018 15:12:38 +0200
fixes url completion segfaulting for empty strings (in case the user hasn't already started typing an URL)
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 | * |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
4 | * Copyright 2018 Olaf Wintermann. All rights reserved. |
76
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"; |
127
7072a2b4ae35
renamed GET to SELECT in davql syntax
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
44 | case DAVQL_SELECT: return "SELECT"; |
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
|
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) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
52 | case DAVQL_UNDEFINED_TYPE: 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"; |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
78 | case DAVQL_CALL: return "function call"; case DAVQL_ARGLIST: return ","; |
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
|
79 | 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
|
80 | 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
|
81 | 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
|
82 | 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
|
83 | 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
|
84 | 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
|
85 | 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
|
86 | 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
|
87 | 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
|
88 | 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
|
89 | 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
|
90 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
91 | } |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
92 | |
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
|
93 | static void dav_debug_ql_fnames_print(DavQLStatement *stmt) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
94 | if (stmt->fields) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
95 | printf("Field names: "); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
96 | UCX_FOREACH(field, stmt->fields) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
97 | DavQLField *f = field->data; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
98 | printf("%.*s, ", sfmtarg(f->name)); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
99 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
100 | printf("\b\b \b\b\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
|
101 | } |
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
|
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
|
103 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
104 | 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
|
105 | // Basic information |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | 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
|
110 | 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
|
111 | 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
|
112 | 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
|
113 | case '-': specialfield = 2; break; |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
114 | } |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
115 | } |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
116 | } |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
117 | if (specialfield) { |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
118 | fieldcount--; |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
119 | } |
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
|
120 | 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
|
121 | sfmtarg(stmt->srctext), |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
122 | _map_querytype(stmt->type), |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
123 | 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
|
124 | _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
|
125 | |
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
|
126 | 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
|
127 | 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
|
128 | 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
|
129 | stmt->where ? "yes" : "no"); |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
130 | |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
131 | // WITH attributes |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
132 | 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
|
133 | 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
|
134 | } 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
|
135 | printf("Depth: placeholder\n"); |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
136 | } else { |
85
0ab1cf261a44
improved grammar + changed depth default, type and added infinity
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
137 | 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
|
138 | } |
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
|
139 | |
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 | // 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
|
141 | 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
|
142 | 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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | } |
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
|
149 | } 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
|
150 | 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
|
151 | } |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
152 | |
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
153 | // error messages |
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
154 | if (stmt->errorcode) { |
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
155 | 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
|
156 | 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
|
157 | } |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
158 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
159 | |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
160 | 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
|
161 | if (!expr) { |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
162 | 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
|
163 | return 0; |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
164 | } else { |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
165 | return 1; |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
166 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
167 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
168 | |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
169 | 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
|
170 | 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
|
171 | 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
|
172 | 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
|
173 | "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
|
174 | 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
|
175 | _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
|
176 | _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
|
177 | 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
|
178 | 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
|
179 | 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
|
180 | 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
|
181 | } |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
182 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
183 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
184 | |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
185 | static void dav_debug_ql_field_print(DavQLField *field) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
186 | if (field) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
187 | printf("Name: %.*s\n", sfmtarg(field->name)); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
188 | if (field->expr) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
189 | dav_debug_ql_expr_print(field->expr); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
190 | } else { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
191 | printf("No expression.\n"); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
192 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
193 | } else { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
194 | printf("No field selected.\n"); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
195 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
196 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
197 | |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
198 | static void dav_debug_ql_tree_print(DavQLExpression *expr, int depth) { |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
199 | if (expr) { |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
200 | if (expr->left) { |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
201 | printf("%*c%s\n", depth, ' ', _map_operator(expr->op)); |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
202 | dav_debug_ql_tree_print(expr->left, depth+1); |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
203 | dav_debug_ql_tree_print(expr->right, depth+1); |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
204 | } else if (expr->type == DAVQL_UNARY) { |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
205 | printf("%*c%s %.*s\n", depth, ' ', _map_operator(expr->op), |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
206 | sfmtarg(expr->srctext)); |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
207 | } else { |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
208 | printf("%*c%.*s\n", depth, ' ', sfmtarg(expr->srctext)); |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
209 | } |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
210 | } |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
211 | } |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
212 | |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
213 | #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
|
214 | #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
|
215 | #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
|
216 | #define DQLD_CMD_PF 3 |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
217 | #define DQLD_CMD_PT 4 |
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
|
218 | #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
|
219 | #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
|
220 | #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
|
221 | #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
|
222 | #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
|
223 | #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
|
224 | #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
|
225 | #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
|
226 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
227 | 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
|
228 | printf("> "); |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
229 | |
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
|
230 | 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
|
231 | 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
|
232 | // 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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | } |
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
|
237 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
238 | 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
|
239 | return DQLD_CMD_Q; |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
240 | } 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
|
241 | 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
|
242 | } 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
|
243 | 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
|
244 | } 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
|
245 | return DQLD_CMD_PF; |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
246 | } else if (!strcmp(buffer, "pt\n")) { |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
247 | return DQLD_CMD_PT; |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
248 | } 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
|
249 | 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
|
250 | } 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
|
251 | return DQLD_CMD_R; |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
252 | } 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
|
253 | 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
|
254 | } 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
|
255 | 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
|
256 | } 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
|
257 | 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
|
258 | } 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
|
259 | 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
|
260 | } 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
|
261 | 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
|
262 | } 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
|
263 | return DQLD_CMD_P; |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
264 | } else { |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
265 | return -1; |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
266 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
267 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
268 | |
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
|
269 | 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
|
270 | if (!stmt) { |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
271 | 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
|
272 | return; |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
273 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
274 | |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
275 | 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
|
276 | 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
|
277 | |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
278 | if (stmt->errorcode) { |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
279 | return; |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
280 | } |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
281 | |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
282 | 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
|
283 | 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
|
284 | 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
|
285 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
286 | while(1) { |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
287 | 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
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | case DQLD_CMD_PE: dav_debug_ql_expr_print(examineexpr); break; |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
292 | case DQLD_CMD_PT: dav_debug_ql_tree_print(examineexpr, 1); 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
|
293 | 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
|
294 | case DQLD_CMD_F: |
356
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
295 | examineclause = DQLD_CMD_F; |
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
296 | examineelem = stmt->fields; |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
297 | if (stmt->fields) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
298 | DavQLField* field = ((DavQLField*)stmt->fields->data); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
299 | examineexpr = field->expr; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
300 | dav_debug_ql_field_print(field); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
301 | } else { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
302 | examineexpr = NULL; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
303 | } |
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
|
304 | 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
|
305 | 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
|
306 | 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
|
307 | 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
|
308 | 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
|
309 | 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
|
310 | case DQLD_CMD_O: |
356
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
311 | examineclause = DQLD_CMD_O; |
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
312 | examineelem = stmt->orderby; |
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
313 | examineexpr = stmt->orderby ? |
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
314 | ((DavQLOrderCriterion*)stmt->orderby->data)->column : NULL; |
699781a1d6fd
davql debugger now reacts on repetitive calls of 'f' and 'o' commands
Mike Becker <universe@uap-core.de>
parents:
291
diff
changeset
|
315 | dav_debug_ql_expr_print(examineexpr); |
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
|
316 | 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
|
317 | 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
|
318 | 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
|
319 | 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
|
320 | 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
|
321 | 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
|
322 | 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
|
323 | 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
|
324 | 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
|
325 | 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
|
326 | examineelem->data)->column; |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
327 | dav_debug_ql_expr_print(examineexpr); |
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
|
328 | } else if (examineclause == DQLD_CMD_F) { |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
329 | DavQLField* field = (DavQLField*)examineelem->data; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
330 | examineexpr = field->expr; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
331 | dav_debug_ql_field_print(field); |
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 | } 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
|
333 | 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
|
334 | } |
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 | } 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
|
336 | 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
|
337 | } |
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
|
338 | } 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
|
339 | 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
|
340 | } |
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
|
341 | break; |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
342 | 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
|
343 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | } else { |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
348 | 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
|
349 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
350 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
351 | break; |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
352 | 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
|
353 | 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
|
354 | 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
|
355 | 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
|
356 | 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
|
357 | } else { |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
358 | 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
|
359 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
360 | } |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
361 | break; |
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
362 | case DQLD_CMD_H: |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
363 | printf( |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
364 | "\nCommands:\n" |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
365 | "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
|
366 | "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
|
367 | "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
|
368 | "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
|
369 | "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
|
370 | "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
|
371 | "(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
|
372 | "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
|
373 | "(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
|
374 | "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
|
375 | "\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
|
376 | "pe: print expression information\n" |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
377 | "pt: print full syntax tree of current (sub-)expression\n" |
80
a2832c054c98
added path examination to debugger + changed field names of expression subtrees
Mike Becker <universe@uap-core.de>
parents:
79
diff
changeset
|
378 | "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
|
379 | "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
|
380 | break; |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
381 | default: printf("unknown command\n"); |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
382 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
383 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
384 | } |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
385 | |
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
|
386 | // ------------------------------------------------------------------------ |
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 | // 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
|
388 | // ------------------------------------------------------------------------ |
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 | |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
390 | #define _error_context "(%.*s[->]%.*s%.*s)" |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
391 | #define _error_invalid "invalid statement" |
121
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
392 | #define _error_out_of_memory "out of memory" |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
393 | #define _error_unexpected_token "unexpected token " _error_context |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
394 | #define _error_invalid_token "invalid token " _error_context |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
395 | #define _error_missing_path "expected path " _error_context |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
396 | #define _error_missing_from "expecting FROM keyword " _error_context |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
397 | #define _error_missing_at "expecting AT keyword " _error_context |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
398 | #define _error_missing_by "expecting BY keyword " _error_context |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
399 | #define _error_missing_as "expecting alias ('as <identifier>') " _error_context |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
400 | #define _error_missing_identifier "expecting identifier " _error_context |
111
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
401 | #define _error_missing_par "missing closed parenthesis " _error_context |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
402 | #define _error_missing_assign "expecting assignment ('=') " _error_context |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
403 | #define _error_missing_where "SET statements must have a WHERE clause or " \ |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
404 | "explicitly use ANYWHERE " _error_context |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
405 | #define _error_invalid_depth "invalid depth " _error_context |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
406 | #define _error_missing_expr "missing expression " _error_context |
108
0199f13c7fe2
fixed parsing of binary expressions did not yield the correct type
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
407 | #define _error_invalid_expr "invalid expression " _error_context |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
408 | #define _error_invalid_unary_op "invalid unary operator " _error_context |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
409 | #define _error_invalid_logical_op "invalid logical operator " _error_context |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
410 | #define _error_invalid_fmtspec "invalid format specifier " _error_context |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
411 | #define _error_invalid_string "string expected " _error_context |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
412 | #define _error_invalid_order_criterion "invalid order criterion " _error_context |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
413 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
414 | #define token_sstr(token) (((DavQLToken*)(token)->data)->value) |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
415 | |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
416 | 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
|
417 | DavQLStatement *stmt, UcxList *token) { |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
418 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
419 | // we try to achieve two things: get as many information as possible |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
420 | // and recover the concrete source string (and not the token strings) |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
421 | sstr_t emptystring = ST(""); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
422 | sstr_t prev = token->prev ? (token->prev->prev ? |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
423 | token_sstr(token->prev->prev) : token_sstr(token->prev)) |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
424 | : emptystring; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
425 | sstr_t tokenstr = token_sstr(token); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
426 | sstr_t next = token->next ? (token->next->next ? |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
427 | token_sstr(token->next->next) : token_sstr(token->next)) |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
428 | : emptystring; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
429 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
430 | int lp = prev.length == 0 ? 0 : tokenstr.ptr-prev.ptr; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
431 | char *pn = tokenstr.ptr + tokenstr.length; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
432 | int ln = next.ptr+next.length - pn; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
433 | |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
434 | stmt->errorcode = errorcode; |
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
435 | stmt->errormessage = ucx_sprintf(errormsg, |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
436 | lp, prev.ptr, |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
437 | sfmtarg(tokenstr), |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
438 | ln, pn).ptr; |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
439 | } |
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
440 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
441 | #define dqlsec_alloc_failed(ptr, stmt) \ |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
442 | if (!(ptr)) do { \ |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
443 | (stmt)->errorcode = DAVQL_ERROR_OUT_OF_MEMORY; \ |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
444 | return 0; \ |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
445 | } while(0) |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
446 | #define dqlsec_malloc(stmt, ptr, type) \ |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
447 | dqlsec_alloc_failed(ptr = malloc(sizeof(type)), stmt) |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
448 | #define dqlsec_mallocz(stmt, ptr, type) \ |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
449 | dqlsec_alloc_failed(ptr = calloc(1, sizeof(type)), stmt) |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
450 | |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
451 | #define dqlsec_list_append_or_free(stmt, list, data) \ |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
452 | do { \ |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
453 | UcxList *_dqlsecbak_ = list; \ |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
454 | list = ucx_list_append(list, data); \ |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
455 | if (!list) { \ |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
456 | free(data); \ |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
457 | data = NULL; \ |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
458 | (stmt)->errorcode = DAVQL_ERROR_OUT_OF_MEMORY; \ |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
459 | list = _dqlsecbak_; \ |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
460 | return 0; \ |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
461 | } \ |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
462 | } while(0) |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
463 | |
96
896022673e0e
special path parser + typed literals + order by parser + grammar changes
Mike Becker <universe@uap-core.de>
parents:
95
diff
changeset
|
464 | // 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
|
465 | static const char *special_token_symbols = ",()+-*/&|^~=!<>"; |
2176ffbf1346
added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
466 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
467 | static _Bool iskeyword(DavQLToken *token) { |
127
7072a2b4ae35
renamed GET to SELECT in davql syntax
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
468 | sstr_t keywords[] ={ST("select"), ST("set"), ST("from"), ST("at"), ST("as"), |
131
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
469 | ST("where"), ST("anywhere"), ST("like"), ST("unlike"), ST("and"), |
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
470 | ST("or"), ST("not"), ST("xor"), ST("with"), ST("infinity"), |
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
471 | ST("order"), ST("by"), ST("asc"), ST("desc") |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
472 | }; |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
473 | for (int i = 0 ; i < sizeof(keywords)/sizeof(sstr_t) ; i++) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
474 | if (!sstrcasecmp(token->value, keywords[i])) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
475 | return 1; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
476 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
477 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
478 | return 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
479 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
480 | |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
481 | static _Bool islongoperator(DavQLToken *token) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
482 | sstr_t operators[] = {ST("and"), ST("or"), ST("not"), ST("xor"), |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
483 | ST("like"), ST("unlike") |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
484 | }; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
485 | for (int i = 0 ; i < sizeof(operators)/sizeof(sstr_t) ; i++) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
486 | if (!sstrcasecmp(token->value, operators[i])) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
487 | return 1; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
488 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
489 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
490 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
491 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
492 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
493 | static UcxList* dav_parse_add_token(UcxList *tokenlist, DavQLToken *token) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
494 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
495 | // determine token class (order of if-statements is very important!) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
496 | char firstchar = token->value.ptr[0]; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
497 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
498 | if (isdigit(firstchar)) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
499 | token->tokenclass = DAVQL_TOKEN_NUMBER; |
263
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
500 | // check, if all characters are digits |
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
501 | for (size_t i = 1 ; i < token->value.length ; i++) { |
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
502 | if (!isdigit(token->value.ptr[i])) { |
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
503 | token->tokenclass = DAVQL_TOKEN_INVALID; |
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
504 | break; |
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
505 | } |
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
506 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
507 | } else if (firstchar == '%') { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
508 | token->tokenclass = DAVQL_TOKEN_FMTSPEC; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
509 | } else if (token->value.length == 1) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
510 | switch (firstchar) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
511 | case '(': token->tokenclass = DAVQL_TOKEN_OPENP; break; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
512 | case ')': token->tokenclass = DAVQL_TOKEN_CLOSEP; break; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
513 | case ',': token->tokenclass = DAVQL_TOKEN_COMMA; break; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
514 | default: |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
515 | token->tokenclass = strchr(special_token_symbols, firstchar) ? |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
516 | DAVQL_TOKEN_OPERATOR : DAVQL_TOKEN_IDENTIFIER; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
517 | } |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
518 | } else if (islongoperator(token)) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
519 | token->tokenclass = DAVQL_TOKEN_OPERATOR; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
520 | } else if (firstchar == '\'') { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
521 | token->tokenclass = DAVQL_TOKEN_STRING; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
522 | } else if (firstchar == '`') { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
523 | token->tokenclass = DAVQL_TOKEN_IDENTIFIER; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
524 | } else if (iskeyword(token)) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
525 | token->tokenclass = DAVQL_TOKEN_KEYWORD; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
526 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
527 | token->tokenclass = DAVQL_TOKEN_IDENTIFIER; |
263
f24b730cb75e
token parser checks if token of class DAVQL_TOKEN_NUMBER consists of digits only
Mike Becker <universe@uap-core.de>
parents:
185
diff
changeset
|
528 | // TODO: check for illegal characters |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
529 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
530 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
531 | // remove quotes (extreme cool feature) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
532 | if (token->tokenclass == DAVQL_TOKEN_STRING || |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
533 | (token->tokenclass == DAVQL_TOKEN_IDENTIFIER && firstchar == '`')) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
534 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
535 | char lastchar = token->value.ptr[token->value.length-1]; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
536 | if (firstchar == lastchar) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
537 | token->value.ptr++; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
538 | token->value.length -= 2; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
539 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
540 | token->tokenclass = DAVQL_TOKEN_INVALID; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
541 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
542 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
543 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
544 | |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
545 | UcxList *ret = ucx_list_append(tokenlist, token); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
546 | if (ret) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
547 | return ret; |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
548 | } else { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
549 | ucx_list_free(tokenlist); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
550 | return NULL; |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
551 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
552 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
553 | |
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
|
554 | static UcxList* dav_parse_tokenize(sstr_t src) { |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
555 | #define alloc_token() do {token = malloc(sizeof(DavQLToken));\ |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
556 | if(!token) {ucx_list_free(tokens); return NULL;}} while(0) |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
557 | #define add_token() do {tokens = dav_parse_add_token(tokens, token); \ |
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
558 | if(!tokens) {return NULL;}} while(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
|
559 | 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
|
560 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
561 | DavQLToken *token = NULL; |
88
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
562 | 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
|
563 | 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
|
564 | // quoted strings / identifiers are a single token |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
565 | if (src.ptr[i] == '\'' || src.ptr[i] == '`') { |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
566 | if (src.ptr[i] == insequence) { |
130
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
567 | // lookahead for escaped string quotes |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
568 | if (src.ptr[i] == '\'' && i+2 < src.length && |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
569 | src.ptr[i+1] == src.ptr[i] && src.ptr[i+2] == src.ptr[i]) { |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
570 | token->value.length += 3; |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
571 | i += 2; |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
572 | } else { |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
573 | // add quoted token to list |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
574 | token->value.length++; |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
575 | add_token(); |
130
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
576 | token = NULL; |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
577 | insequence = '\0'; |
80d273229f24
fixed grammar for path + added missing string quote escaping (still not perfect: escape sequence is in syntax tree)
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
578 | } |
88
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
579 | } else if (insequence == '\0') { |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
580 | insequence = src.ptr[i]; |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
581 | // always create new token for quoted strings |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
582 | if (token) { |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
583 | add_token(); |
88
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
584 | } |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
585 | alloc_token(); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
586 | token->value.ptr = src.ptr + i; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
587 | token->value.length = 1; |
88
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
588 | } else { |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
589 | // add other kind of quotes to token |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
590 | token->value.length++; |
88
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
591 | } |
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
592 | } else if (insequence) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
593 | token->value.length++; |
88
4d6b03bd7034
tokenizer now correctly handles quoted tokens
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
594 | } 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
|
595 | // 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
|
596 | if (token) { |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
597 | add_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
|
598 | 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
|
599 | } |
93
2176ffbf1346
added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
600 | } 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
|
601 | // 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
|
602 | if (token) { |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
603 | add_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
|
604 | 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
|
605 | } |
93
2176ffbf1346
added special symbol list to tokenizer
Mike Becker <universe@uap-core.de>
parents:
92
diff
changeset
|
606 | // add special symbol as single token to list |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
607 | alloc_token(); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
608 | token->value.ptr = src.ptr + i; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
609 | token->value.length = 1; |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
610 | add_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
|
611 | // 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
|
612 | 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
|
613 | } 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
|
614 | // 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
|
615 | if (!token) { |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
616 | alloc_token(); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
617 | token->value.ptr = src.ptr + i; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
618 | token->value.length = 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
|
619 | } |
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
|
620 | // extend token length when reading more bytes |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
621 | token->value.length++; |
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
|
622 | } |
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
|
623 | } |
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
|
624 | |
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
|
625 | if (token) { |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
626 | add_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
|
627 | } |
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
|
628 | |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
629 | alloc_token(); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
630 | token->tokenclass = DAVQL_TOKEN_END; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
631 | token->value = S(""); |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
632 | UcxList *ret = ucx_list_append(tokens, token); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
633 | if (ret) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
634 | return ret; |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
635 | } else { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
636 | ucx_list_free(tokens); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
637 | return NULL; |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
638 | } |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
639 | #undef alloc_token |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
640 | #undef add_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
|
641 | } |
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
|
642 | |
87
ed21d95984bb
removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
643 | static void dav_free_expression(DavQLExpression *expr) { |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
644 | if (expr) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
645 | if (expr->left) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
646 | dav_free_expression(expr->left); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
647 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
648 | if (expr->right) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
649 | dav_free_expression(expr->right); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
650 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
651 | free(expr); |
87
ed21d95984bb
removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
652 | } |
ed21d95984bb
removed DavQLExpression type for path (since it always is an identifier)
Mike Becker <universe@uap-core.de>
parents:
86
diff
changeset
|
653 | } |
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
|
654 | |
99
579238097973
fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
655 | 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
|
656 | dav_free_expression(field->expr); |
579238097973
fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
657 | free(field); |
579238097973
fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
658 | } |
579238097973
fieldlist parser can now parse fields with alias
Mike Becker <universe@uap-core.de>
parents:
98
diff
changeset
|
659 | |
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
|
660 | 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
|
661 | 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
|
662 | 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
|
663 | } |
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
|
664 | 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
|
665 | } |
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
|
666 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
667 | #define token_is(token, expectedclass) (token && \ |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
668 | (((DavQLToken*)(token)->data)->tokenclass == expectedclass)) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
669 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
670 | #define tokenvalue_is(token, expectedvalue) (token && \ |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
671 | !sstrcasecmp(((DavQLToken*)(token)->data)->value, S(expectedvalue))) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
672 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
673 | typedef int(*exprparser_f)(DavQLStatement*,UcxList*,DavQLExpression*); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
674 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
675 | static int dav_parse_binary_expr(DavQLStatement* stmt, UcxList* token, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
676 | DavQLExpression* expr, exprparser_f parseL, char* opc, int* opv, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
677 | exprparser_f parseR) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
678 | |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
679 | if (!token) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
680 | return 0; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
681 | } |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
682 | |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
683 | int total_consumed = 0, consumed; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
684 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
685 | // save temporarily on stack (copy to heap later on) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
686 | DavQLExpression left, right; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
687 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
688 | // RULE: LEFT, [Operator, RIGHT] |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
689 | memset(&left, 0, sizeof(DavQLExpression)); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
690 | consumed = parseL(stmt, token, &left); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
691 | if (!consumed || stmt->errorcode) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
692 | return 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
693 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
694 | total_consumed += consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
695 | token = ucx_list_get(token, consumed); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
696 | |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
697 | char *op; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
698 | if (token_is(token, DAVQL_TOKEN_OPERATOR) && |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
699 | (op = strchr(opc, token_sstr(token).ptr[0]))) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
700 | expr->op = opv[op-opc]; |
108
0199f13c7fe2
fixed parsing of binary expressions did not yield the correct type
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
701 | expr->type = DAVQL_BINARY; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
702 | total_consumed++; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
703 | token = token->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
704 | memset(&right, 0, sizeof(DavQLExpression)); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
705 | consumed = parseR(stmt, token, &right); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
706 | if (stmt->errorcode) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
707 | return 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
708 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
709 | if (!consumed) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
710 | dav_error_in_context(DAVQL_ERROR_MISSING_EXPR, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
711 | _error_missing_expr, stmt, token); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
712 | return 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
713 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
714 | total_consumed += consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
715 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
716 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
717 | if (expr->op == DAVQL_NOOP) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
718 | memcpy(expr, &left, sizeof(DavQLExpression)); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
719 | } else { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
720 | dqlsec_malloc(stmt, expr->left, DavQLExpression); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
721 | memcpy(expr->left, &left, sizeof(DavQLExpression)); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
722 | dqlsec_malloc(stmt, expr->right, DavQLExpression); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
723 | memcpy(expr->right, &right, sizeof(DavQLExpression)); |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
724 | |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
725 | expr->srctext.ptr = expr->left->srctext.ptr; |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
726 | expr->srctext.length = |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
727 | expr->right->srctext.ptr - |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
728 | expr->left->srctext.ptr + expr->right->srctext.length; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
729 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
730 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
731 | return total_consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
732 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
733 | |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
734 | static void dav_add_fmt_args(DavQLStatement *stmt, sstr_t str) { |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
735 | int placeholder = 0; |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
736 | for (size_t i=0;i<str.length;i++) { |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
737 | char c = str.ptr[i]; |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
738 | if (placeholder) { |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
739 | if (c != '%') { |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
740 | stmt->args = ucx_list_append( |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
741 | stmt->args, |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
742 | (void*)(intptr_t)c); |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
743 | } |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
744 | placeholder = 0; |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
745 | } else if (c == '%') { |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
746 | placeholder = 1; |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
747 | } |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
748 | } |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
749 | } |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
750 | |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
751 | static int dav_parse_literal(DavQLStatement* stmt, UcxList* token, |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
752 | DavQLExpression* expr) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
753 | |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
754 | expr->srctext = token_sstr(token); |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
755 | if (token_is(token, DAVQL_TOKEN_NUMBER)) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
756 | expr->type = DAVQL_NUMBER; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
757 | } else if (token_is(token, DAVQL_TOKEN_STRING)) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
758 | expr->type = DAVQL_STRING; |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
759 | // check for format specifiers and add args |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
760 | dav_add_fmt_args(stmt, expr->srctext); |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
761 | } else if (token_is(token, DAVQL_TOKEN_TIMESTAMP)) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
762 | expr->type = DAVQL_TIMESTAMP; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
763 | } else if (token_is(token, DAVQL_TOKEN_FMTSPEC) |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
764 | && expr->srctext.length == 2) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
765 | switch (expr->srctext.ptr[1]) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
766 | case 'd': expr->type = DAVQL_NUMBER; break; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
767 | case 's': expr->type = DAVQL_STRING; break; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
768 | case 't': expr->type = DAVQL_TIMESTAMP; break; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
769 | default: |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
770 | dav_error_in_context(DAVQL_ERROR_INVALID_FMTSPEC, |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
771 | _error_invalid_fmtspec, stmt, token); |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
772 | return 0; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
773 | } |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
774 | // add fmtspec type to query arg list |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
775 | stmt->args = ucx_list_append(stmt->args, (void*)(intptr_t)expr->srctext.ptr[1]); |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
776 | } else { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
777 | return 0; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
778 | } |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
779 | |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
780 | return 1; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
781 | } |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
782 | |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
783 | // forward declaration |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
784 | static int dav_parse_expression(DavQLStatement* stmt, UcxList* token, |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
785 | DavQLExpression* expr); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
786 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
787 | static int dav_parse_arglist(DavQLStatement* stmt, UcxList* token, |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
788 | DavQLExpression* expr) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
789 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
790 | expr->srctext.ptr = token_sstr(token).ptr; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
791 | expr->srctext.length = 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
792 | expr->left = expr->right = NULL; // in case we fail, we want them to be sane |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
793 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
794 | int total_consumed = 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
795 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
796 | // RULE: Expression, {",", Expression}; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
797 | DavQLExpression *arglist = expr; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
798 | DavQLExpression arg; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
799 | char *lastchar = expr->srctext.ptr; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
800 | int consumed; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
801 | do { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
802 | memset(&arg, 0, sizeof(DavQLExpression)); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
803 | consumed = dav_parse_expression(stmt, token, &arg); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
804 | if (consumed) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
805 | lastchar = arg.srctext.ptr + arg.srctext.length; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
806 | total_consumed += consumed; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
807 | token = ucx_list_get(token, consumed); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
808 | // look ahead for a comma |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
809 | if (token_is(token, DAVQL_TOKEN_COMMA)) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
810 | total_consumed++; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
811 | token = token->next; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
812 | /* we have more arguments, so put the current argument to the |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
813 | * left subtree and create a new node to the right |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
814 | */ |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
815 | dqlsec_malloc(stmt, arglist->left, DavQLExpression); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
816 | memcpy(arglist->left, &arg, sizeof(DavQLExpression)); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
817 | arglist->srctext.ptr = arg.srctext.ptr; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
818 | arglist->op = DAVQL_ARGLIST; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
819 | arglist->type = DAVQL_FUNCCALL; |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
820 | dqlsec_mallocz(stmt, arglist->right, DavQLExpression); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
821 | arglist = arglist->right; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
822 | } else { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
823 | // this was the last argument, so write it to the current node |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
824 | memcpy(arglist, &arg, sizeof(DavQLExpression)); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
825 | consumed = 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
826 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
827 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
828 | } while (consumed && !stmt->errorcode); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
829 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
830 | // recover source text |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
831 | arglist = expr; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
832 | while (arglist && arglist->type == DAVQL_FUNCCALL) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
833 | arglist->srctext.length = lastchar - arglist->srctext.ptr; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
834 | arglist = arglist->right; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
835 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
836 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
837 | return total_consumed; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
838 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
839 | |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
840 | static int dav_parse_funccall(DavQLStatement* stmt, UcxList* token, |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
841 | DavQLExpression* expr) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
842 | |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
843 | // RULE: Identifier, "(", ArgumentList, ")"; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
844 | if (token_is(token, DAVQL_TOKEN_IDENTIFIER) && |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
845 | token_is(token->next, DAVQL_TOKEN_OPENP)) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
846 | |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
847 | expr->type = DAVQL_FUNCCALL; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
848 | expr->op = DAVQL_CALL; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
849 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
850 | dqlsec_mallocz(stmt, expr->left, DavQLExpression); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
851 | expr->left->type = DAVQL_IDENTIFIER; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
852 | expr->left->srctext = token_sstr(token); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
853 | expr->right = NULL; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
854 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
855 | token = token->next->next; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
856 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
857 | DavQLExpression arg; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
858 | int argtokens = dav_parse_arglist(stmt, token, &arg); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
859 | if (stmt->errorcode) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
860 | // if an error occurred while parsing the arglist, return now |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
861 | return 2; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
862 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
863 | if (argtokens) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
864 | token = ucx_list_get(token, argtokens); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
865 | dqlsec_malloc(stmt, expr->right, DavQLExpression); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
866 | memcpy(expr->right, &arg, sizeof(DavQLExpression)); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
867 | } else { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
868 | // arg list may be empty |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
869 | expr->right = NULL; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
870 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
871 | |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
872 | if (token_is(token, DAVQL_TOKEN_CLOSEP)) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
873 | return 3 + argtokens; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
874 | } else { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
875 | dav_error_in_context(DAVQL_ERROR_MISSING_PAR, _error_missing_par, |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
876 | stmt, token); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
877 | return 2; // it MUST be a function call, but it is invalid |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
878 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
879 | } else { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
880 | return 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
881 | } |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
882 | } |
111
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
883 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
884 | static int dav_parse_unary_expr(DavQLStatement* stmt, UcxList* token, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
885 | DavQLExpression* expr) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
886 | |
111
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
887 | UcxList *firsttoken = token; // save for srctext recovery |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
888 | |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
889 | DavQLExpression* atom = expr; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
890 | int total_consumed = 0; |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
891 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
892 | // optional unary operator |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
893 | if (token_is(token, DAVQL_TOKEN_OPERATOR)) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
894 | char *op = strchr("+-~", token_sstr(token).ptr[0]); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
895 | if (op) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
896 | expr->type = DAVQL_UNARY; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
897 | switch (*op) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
898 | case '+': expr->op = DAVQL_ADD; break; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
899 | case '-': expr->op = DAVQL_SUB; break; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
900 | case '~': expr->op = DAVQL_NEG; break; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
901 | } |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
902 | dqlsec_mallocz(stmt, expr->left, DavQLExpression); |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
903 | atom = expr->left; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
904 | total_consumed++; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
905 | token = token->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
906 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
907 | dav_error_in_context(DAVQL_ERROR_INVALID_UNARY_OP, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
908 | _error_invalid_unary_op, stmt, token); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
909 | return 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
910 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
911 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
912 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
913 | // RULE: (ParExpression | AtomicExpression) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
914 | if (token_is(token, DAVQL_TOKEN_OPENP)) { |
111
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
915 | token = token->next; total_consumed++; |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
916 | // RULE: "(", Expression, ")" |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
917 | int consumed = dav_parse_expression(stmt, token, atom); |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
918 | if (stmt->errorcode) { |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
919 | return 0; |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
920 | } |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
921 | if (!consumed) { |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
922 | dav_error_in_context(DAVQL_ERROR_INVALID_EXPR, |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
923 | _error_invalid_expr, stmt, token); |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
924 | return 0; |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
925 | } |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
926 | token = ucx_list_get(token, consumed); |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
927 | total_consumed += consumed; |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
928 | if (token_is(token, DAVQL_TOKEN_CLOSEP)) { |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
929 | token = token->next; total_consumed++; |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
930 | } else { |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
931 | dav_error_in_context(DAVQL_ERROR_MISSING_PAR, |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
932 | _error_missing_par, stmt, token); |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
933 | return 0; |
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
934 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
935 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
936 | // RULE: FunctionCall |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
937 | int consumed = dav_parse_funccall(stmt, token, atom); |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
938 | if (consumed) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
939 | total_consumed += consumed; |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
940 | } else if (token_is(token, DAVQL_TOKEN_IDENTIFIER)) { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
941 | // RULE: Identifier |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
942 | total_consumed++; |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
943 | atom->type = DAVQL_IDENTIFIER; |
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
944 | atom->srctext = token_sstr(token); |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
945 | } else { |
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
946 | // RULE: Literal |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
947 | total_consumed += dav_parse_literal(stmt, token, atom); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
948 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
949 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
950 | |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
951 | // recover source text |
111
39f4c5fcaa60
parser for ParExpression
Mike Becker <universe@uap-core.de>
parents:
109
diff
changeset
|
952 | expr->srctext.ptr = token_sstr(firsttoken).ptr; |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
953 | if (total_consumed > 0) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
954 | sstr_t lasttoken = |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
955 | token_sstr(ucx_list_get(firsttoken, total_consumed-1)); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
956 | expr->srctext.length = |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
957 | lasttoken.ptr - expr->srctext.ptr + lasttoken.length; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
958 | } else { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
959 | // the expression should not be used anyway, but we want to be safe |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
960 | expr->srctext.length = 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
961 | } |
109
020a5b5aa510
added syntax tree display to debugger + expression parser saves source text in every node
Mike Becker <universe@uap-core.de>
parents:
108
diff
changeset
|
962 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
963 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
964 | return total_consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
965 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
966 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
967 | static int dav_parse_bitexpr(DavQLStatement* stmt, UcxList* token, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
968 | DavQLExpression* expr) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
969 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
970 | return dav_parse_binary_expr(stmt, token, expr, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
971 | dav_parse_unary_expr, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
972 | "&|^", (int[]){DAVQL_AND, DAVQL_OR, DAVQL_XOR}, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
973 | dav_parse_bitexpr); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
974 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
975 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
976 | static int dav_parse_multexpr(DavQLStatement* stmt, UcxList* token, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
977 | DavQLExpression* expr) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
978 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
979 | return dav_parse_binary_expr(stmt, token, expr, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
980 | dav_parse_bitexpr, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
981 | "*/", (int[]){DAVQL_MUL, DAVQL_DIV}, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
982 | dav_parse_multexpr); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
983 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
984 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
985 | static int dav_parse_expression(DavQLStatement* stmt, UcxList* token, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
986 | DavQLExpression* expr) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
987 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
988 | return dav_parse_binary_expr(stmt, token, expr, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
989 | dav_parse_multexpr, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
990 | "+-", (int[]){DAVQL_ADD, DAVQL_SUB}, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
991 | dav_parse_expression); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
992 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
993 | |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
994 | static int dav_parse_named_field(DavQLStatement *stmt, UcxList *token, |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
995 | DavQLField *field) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
996 | int total_consumed = 0, consumed; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
997 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
998 | // RULE: Expression, " as ", Identifier; |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
999 | DavQLExpression *expr; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1000 | dqlsec_mallocz(stmt, expr, DavQLExpression); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1001 | consumed = dav_parse_expression(stmt, token, expr); |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
1002 | if (stmt->errorcode) { |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
1003 | dav_free_expression(expr); |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
1004 | return 0; |
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
1005 | } |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1006 | if (expr->type == DAVQL_UNDEFINED_TYPE) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1007 | dav_free_expression(expr); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1008 | dav_error_in_context(DAVQL_ERROR_INVALID_EXPR, |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1009 | _error_invalid_expr, stmt, token); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1010 | return 0; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1011 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1012 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1013 | token = ucx_list_get(token, consumed); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1014 | total_consumed += consumed; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1015 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1016 | if (token_is(token, DAVQL_TOKEN_KEYWORD) && tokenvalue_is(token, "as")) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1017 | token = token->next; total_consumed++; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1018 | } else { |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
1019 | dav_free_expression(expr); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1020 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1021 | _error_missing_as, stmt, token); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1022 | return 0; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1023 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1024 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1025 | if (token_is(token, DAVQL_TOKEN_IDENTIFIER)) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1026 | field->name = token_sstr(token); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1027 | field->expr = expr; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1028 | return total_consumed + 1; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1029 | } else { |
114
943548492a47
added function call parser + fixed some memory management mistakes
Mike Becker <universe@uap-core.de>
parents:
113
diff
changeset
|
1030 | dav_free_expression(expr); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1031 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1032 | _error_missing_identifier, stmt, token); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1033 | return 0; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1034 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1035 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1036 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1037 | static int dav_parse_fieldlist(DavQLStatement *stmt, UcxList *token) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1038 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1039 | // RULE: "-" |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1040 | if (token_is(token, DAVQL_TOKEN_OPERATOR) && tokenvalue_is(token, "-")) { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1041 | DavQLField *field; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1042 | dqlsec_malloc(stmt, field, DavQLField); |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
1043 | dqlsec_list_append_or_free(stmt, stmt->fields, field); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1044 | dqlsec_mallocz(stmt, field->expr, DavQLExpression); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1045 | field->expr->type = DAVQL_IDENTIFIER; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1046 | field->expr->srctext = field->name = token_sstr(token); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1047 | return 1; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1048 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1049 | |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1050 | // RULE: "*", {",", NamedExpression} |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1051 | if (token_is(token, DAVQL_TOKEN_OPERATOR) && tokenvalue_is(token, "*")) { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1052 | DavQLField *field; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1053 | dqlsec_malloc(stmt, field, DavQLField); |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
1054 | dqlsec_list_append_or_free(stmt, stmt->fields, field); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1055 | dqlsec_mallocz(stmt, field->expr, DavQLExpression); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1056 | field->expr->type = DAVQL_IDENTIFIER; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1057 | field->expr->srctext = field->name = token_sstr(token); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1058 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1059 | int total_consumed = 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1060 | int consumed = 1; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1061 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1062 | do { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1063 | token = ucx_list_get(token, consumed); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1064 | total_consumed += consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1065 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1066 | if (token_is(token, DAVQL_TOKEN_COMMA)) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1067 | total_consumed++; token = token->next; |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1068 | DavQLField localfield; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1069 | consumed = dav_parse_named_field(stmt, token, &localfield); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1070 | if (!stmt->errorcode && consumed) { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1071 | DavQLField *field; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1072 | dqlsec_malloc(stmt, field, DavQLField); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1073 | memcpy(field, &localfield, sizeof(DavQLField)); |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
1074 | dqlsec_list_append_or_free(stmt, stmt->fields, field); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1075 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1076 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1077 | consumed = 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1078 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1079 | } while (consumed > 0); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1080 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1081 | return total_consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1082 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1083 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1084 | // RULE: FieldExpression, {",", FieldExpression} |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1085 | { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1086 | int total_consumed = 0, consumed; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1087 | do { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1088 | // RULE: NamedField | Identifier |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1089 | DavQLField localfield; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1090 | consumed = dav_parse_named_field(stmt, token, &localfield); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1091 | if (consumed) { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1092 | DavQLField *field; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1093 | dqlsec_malloc(stmt, field, DavQLField); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1094 | memcpy(field, &localfield, sizeof(DavQLField)); |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
1095 | dqlsec_list_append_or_free(stmt, stmt->fields, field); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1096 | token = ucx_list_get(token, consumed); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1097 | total_consumed += consumed; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1098 | } else if (token_is(token, DAVQL_TOKEN_IDENTIFIER) |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1099 | // look ahead, if the field is JUST the identifier |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1100 | && (token_is(token->next, DAVQL_TOKEN_COMMA) || |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1101 | tokenvalue_is(token->next, "from"))) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1102 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1103 | DavQLField *field; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1104 | dqlsec_malloc(stmt, field, DavQLField); |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1105 | dqlsec_mallocz(stmt, field->expr, DavQLExpression); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1106 | field->expr->type = DAVQL_IDENTIFIER; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1107 | field->expr->srctext = field->name = token_sstr(token); |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
1108 | dqlsec_list_append_or_free(stmt, stmt->fields, field); |
113
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1109 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1110 | consumed = 1; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1111 | total_consumed++; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1112 | token = token->next; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1113 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1114 | // we found a valid solution, so erase any errors |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1115 | stmt->errorcode = 0; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1116 | if (stmt->errormessage) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1117 | free(stmt->errormessage); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1118 | stmt->errormessage = NULL; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1119 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1120 | } else { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1121 | // dav_parse_named_field has already thrown a good error |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1122 | consumed = 0; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1123 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1124 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1125 | // field has been parsed, now try to get a comma |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1126 | if (consumed) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1127 | consumed = token_is(token, DAVQL_TOKEN_COMMA) ? 1 : 0; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1128 | if (consumed) { |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1129 | token = token->next; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1130 | total_consumed++; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1131 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1132 | } |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1133 | } while (consumed); |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1134 | |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1135 | return total_consumed; |
412b06dc0162
completed field list parser + error messages do now provide more context information based on the source string
Mike Becker <universe@uap-core.de>
parents:
111
diff
changeset
|
1136 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1137 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1138 | |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1139 | // forward declaration |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1140 | static int dav_parse_logical_expr(DavQLStatement *stmt, UcxList *token, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1141 | DavQLExpression *expr); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1142 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1143 | static int dav_parse_bool_prim(DavQLStatement *stmt, UcxList *token, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1144 | DavQLExpression *expr) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1145 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1146 | expr->type = DAVQL_LOGICAL; |
131
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
1147 | expr->srctext = token_sstr(token); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1148 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1149 | int total_consumed = 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1150 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1151 | DavQLExpression bexpr; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1152 | memset(&bexpr, 0, sizeof(DavQLExpression)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1153 | total_consumed = dav_parse_expression(stmt, token, &bexpr); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1154 | if (!total_consumed || stmt->errorcode) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1155 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1156 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1157 | token = ucx_list_get(token, total_consumed); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1158 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1159 | UcxList* optok = token; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1160 | // RULE: Expression, (" like " | " unlike "), String |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1161 | if (token_is(optok, DAVQL_TOKEN_OPERATOR) && (tokenvalue_is(optok, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1162 | "like") || tokenvalue_is(optok, "unlike"))) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1163 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1164 | total_consumed++; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1165 | token = token->next; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1166 | if (token_is(token, DAVQL_TOKEN_STRING)) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1167 | expr->op = tokenvalue_is(optok, "like") ? |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1168 | DAVQL_LIKE : DAVQL_UNLIKE; |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1169 | dqlsec_malloc(stmt, expr->left, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1170 | memcpy(expr->left, &bexpr, sizeof(DavQLExpression)); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1171 | dqlsec_mallocz(stmt, expr->right, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1172 | expr->right->type = DAVQL_STRING; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1173 | expr->right->srctext = token_sstr(token); |
131
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
1174 | expr->srctext.length = expr->right->srctext.ptr - |
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
1175 | expr->srctext.ptr + expr->right->srctext.length; |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
1176 | |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
1177 | // fmt args |
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
1178 | dav_add_fmt_args(stmt, expr->right->srctext); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1179 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1180 | return total_consumed + 1; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1181 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1182 | dav_error_in_context(DAVQL_ERROR_INVALID_STRING, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1183 | _error_invalid_string, stmt, token); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1184 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1185 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1186 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1187 | // RULE: Expression, Comparison, Expression |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1188 | else if (token_is(optok, DAVQL_TOKEN_OPERATOR) && ( |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1189 | tokenvalue_is(optok, "=") || tokenvalue_is(optok, "!") || |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1190 | tokenvalue_is(optok, "<") || tokenvalue_is(optok, ">"))) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1191 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1192 | total_consumed++; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1193 | token = token->next; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1194 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1195 | if (tokenvalue_is(optok, "=")) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1196 | expr->op = DAVQL_EQ; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1197 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1198 | if (tokenvalue_is(token, "=")) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1199 | if (tokenvalue_is(optok, "!")) { |
125
5e2576b08680
fixed: comparison operator info has been incorrectly written to type field
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
1200 | expr->op = DAVQL_NEQ; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1201 | } else if (tokenvalue_is(optok, "<")) { |
125
5e2576b08680
fixed: comparison operator info has been incorrectly written to type field
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
1202 | expr->op = DAVQL_LE; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1203 | } else if (tokenvalue_is(optok, ">")) { |
125
5e2576b08680
fixed: comparison operator info has been incorrectly written to type field
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
1204 | expr->op = DAVQL_GE; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1205 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1206 | total_consumed++; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1207 | token = token->next; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1208 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1209 | if (tokenvalue_is(optok, "<")) { |
125
5e2576b08680
fixed: comparison operator info has been incorrectly written to type field
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
1210 | expr->op = DAVQL_LT; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1211 | } else if (tokenvalue_is(optok, ">")) { |
125
5e2576b08680
fixed: comparison operator info has been incorrectly written to type field
Mike Becker <universe@uap-core.de>
parents:
122
diff
changeset
|
1212 | expr->op = DAVQL_GT; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1213 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1214 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1215 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1216 | |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1217 | DavQLExpression rexpr; |
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1218 | memset(&rexpr, 0, sizeof(DavQLExpression)); |
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1219 | int consumed = dav_parse_expression(stmt, token, &rexpr); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1220 | if (stmt->errorcode) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1221 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1222 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1223 | if (!consumed) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1224 | dav_error_in_context( |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1225 | DAVQL_ERROR_MISSING_EXPR, _error_missing_expr, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1226 | stmt, token); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1227 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1228 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1229 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1230 | total_consumed += consumed; |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1231 | dqlsec_malloc(stmt, expr->left, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1232 | memcpy(expr->left, &bexpr, sizeof(DavQLExpression)); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1233 | dqlsec_malloc(stmt, expr->right, DavQLExpression); |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1234 | memcpy(expr->right, &rexpr, sizeof(DavQLExpression)); |
131
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
1235 | |
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
1236 | expr->srctext.length = expr->right->srctext.ptr - |
32e7b3e6b482
added missing keywords + fixed missing source text for boolean primaries
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
1237 | expr->srctext.ptr + expr->right->srctext.length; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1238 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1239 | return total_consumed; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1240 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1241 | // RULE: FunctionCall | Identifier; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1242 | else if (bexpr.type == DAVQL_FUNCCALL || bexpr.type == DAVQL_IDENTIFIER) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1243 | memcpy(expr, &bexpr, sizeof(DavQLExpression)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1244 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1245 | return total_consumed; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1246 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1247 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1248 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1249 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1250 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1251 | static int dav_parse_bool_expr(DavQLStatement *stmt, UcxList *token, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1252 | DavQLExpression *expr) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1253 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1254 | // RULE: "not ", LogicalExpression |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1255 | if (token_is(token, DAVQL_TOKEN_OPERATOR) && tokenvalue_is(token, "not")) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1256 | expr->type = DAVQL_LOGICAL; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1257 | expr->op = DAVQL_NOT; |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1258 | dqlsec_mallocz(stmt, expr->left, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1259 | expr->srctext = token_sstr(token); |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1260 | |
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1261 | token = token->next; |
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1262 | int consumed = dav_parse_bool_expr(stmt, token, expr->left); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1263 | if (stmt->errorcode) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1264 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1265 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1266 | if (consumed) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1267 | sstr_t lasttok = token_sstr(ucx_list_get(token, consumed-1)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1268 | expr->srctext.length = |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1269 | lasttok.ptr - expr->srctext.ptr + lasttok.length; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1270 | return consumed + 1; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1271 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1272 | dav_error_in_context(DAVQL_ERROR_MISSING_EXPR, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1273 | _error_missing_expr, stmt, token); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1274 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1275 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1276 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1277 | // RULE: "(", LogicalExpression, ")" |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1278 | else if (token_is(token, DAVQL_TOKEN_OPENP)) { |
118
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1279 | int consumed = dav_parse_logical_expr(stmt, token->next, expr); |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1280 | if (consumed) { |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1281 | token = ucx_list_get(token->next, consumed); |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1282 | |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1283 | if (token_is(token, DAVQL_TOKEN_CLOSEP)) { |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1284 | token = token->next; |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1285 | return consumed + 2; |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1286 | } else { |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1287 | dav_error_in_context(DAVQL_ERROR_MISSING_PAR, _error_missing_par, |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1288 | stmt, token); |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1289 | return 0; |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1290 | } |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1291 | } else { |
118
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1292 | // don't handle errors here, we can also try a boolean primary |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1293 | stmt->errorcode = 0; |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1294 | if (stmt->errormessage) { |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1295 | free(stmt->errormessage); |
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1296 | } |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1297 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1298 | } |
118
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1299 | |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1300 | // RULE: BooleanPrimary |
118
1e2b1005004c
fixed paranthsis ambiguity for logical and normal expressions
Mike Becker <universe@uap-core.de>
parents:
117
diff
changeset
|
1301 | return dav_parse_bool_prim(stmt, token, expr); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1302 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1303 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1304 | static int dav_parse_logical_expr(DavQLStatement *stmt, UcxList *token, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1305 | DavQLExpression *expr) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1306 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1307 | UcxList *firsttoken = token; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1308 | int total_consumed = 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1309 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1310 | // RULE: BooleanLiteral, [LogicalOperator, LogicalExpression]; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1311 | DavQLExpression left, right; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1312 | memset(&left, 0, sizeof(DavQLExpression)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1313 | int consumed = dav_parse_bool_expr(stmt, token, &left); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1314 | if (stmt->errorcode) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1315 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1316 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1317 | if (!consumed) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1318 | dav_error_in_context(DAVQL_ERROR_MISSING_EXPR, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1319 | _error_missing_expr, stmt, token); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1320 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1321 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1322 | total_consumed += consumed; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1323 | token = ucx_list_get(token, consumed); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1324 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1325 | if (token_is(token, DAVQL_TOKEN_OPERATOR)) { |
121
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1326 | expr->type = DAVQL_LOGICAL; |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1327 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1328 | davqloperator_t op = DAVQL_NOOP; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1329 | if (tokenvalue_is(token, "and")) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1330 | op = DAVQL_LAND; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1331 | } else if (tokenvalue_is(token, "or")) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1332 | op = DAVQL_LOR; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1333 | } else if (tokenvalue_is(token, "xor")) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1334 | op = DAVQL_LXOR; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1335 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1336 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1337 | if (op == DAVQL_NOOP) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1338 | dav_error_in_context(DAVQL_ERROR_INVALID_LOGICAL_OP, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1339 | _error_invalid_logical_op, stmt, token); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1340 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1341 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1342 | expr->op = op; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1343 | total_consumed++; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1344 | token = token->next; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1345 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1346 | memset(&right, 0, sizeof(DavQLExpression)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1347 | consumed = dav_parse_logical_expr(stmt, token, &right); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1348 | if (stmt->errorcode) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1349 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1350 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1351 | if (!consumed) { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1352 | dav_error_in_context(DAVQL_ERROR_MISSING_EXPR, |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1353 | _error_missing_expr, stmt, token); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1354 | return 0; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1355 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1356 | total_consumed += consumed; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1357 | token = ucx_list_get(token, consumed); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1358 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1359 | dqlsec_malloc(stmt, expr->left, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1360 | memcpy(expr->left, &left, sizeof(DavQLExpression)); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1361 | dqlsec_malloc(stmt, expr->right, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1362 | memcpy(expr->right, &right, sizeof(DavQLExpression)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1363 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1364 | } else { |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1365 | memcpy(expr, &left, sizeof(DavQLExpression)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1366 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1367 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1368 | // set type and recover source text |
121
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1369 | if (total_consumed > 0) { |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1370 | expr->srctext.ptr = token_sstr(firsttoken).ptr; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1371 | sstr_t lasttok = token_sstr(ucx_list_get(firsttoken, total_consumed-1)); |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1372 | expr->srctext.length = lasttok.ptr-expr->srctext.ptr+lasttok.length; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1373 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1374 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1375 | return total_consumed; |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1376 | } |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1377 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1378 | static int dav_parse_where_clause(DavQLStatement *stmt, UcxList *token) { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1379 | dqlsec_mallocz(stmt, stmt->where, DavQLExpression); |
115
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1380 | |
5744a3dee766
completed logical expression parser - NEED TO TEST A LOT!
Mike Becker <universe@uap-core.de>
parents:
114
diff
changeset
|
1381 | return dav_parse_logical_expr(stmt, token, stmt->where); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1382 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1383 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1384 | static int dav_parse_with_clause(DavQLStatement *stmt, UcxList *token) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1385 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1386 | int total_consumed = 0; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1387 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1388 | // RULE: "depth", "=", (Number | "infinity") |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1389 | if (tokenvalue_is(token, "depth")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1390 | token = token->next; total_consumed++; |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1391 | if (tokenvalue_is(token, "=")) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1392 | token = token->next; total_consumed++; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1393 | if (tokenvalue_is(token, "infinity")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1394 | stmt->depth = DAV_DEPTH_INFINITY; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1395 | token = token->next; total_consumed++; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1396 | } else { |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1397 | DavQLExpression *depthexpr; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1398 | dqlsec_mallocz(stmt, depthexpr, DavQLExpression); |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1399 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1400 | int consumed = dav_parse_expression(stmt, token, depthexpr); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1401 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1402 | if (consumed) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1403 | if (depthexpr->type == DAVQL_NUMBER) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1404 | if (depthexpr->srctext.ptr[0] == '%') { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1405 | stmt->depth = DAV_DEPTH_PLACEHOLDER; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1406 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1407 | sstr_t depthstr = depthexpr->srctext; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1408 | char *conv = malloc(depthstr.length+1); |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1409 | if (!conv) { |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1410 | dav_free_expression(depthexpr); |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1411 | stmt->errorcode = DAVQL_ERROR_OUT_OF_MEMORY; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1412 | return 0; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1413 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1414 | char *chk; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1415 | memcpy(conv, depthstr.ptr, depthstr.length); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1416 | conv[depthstr.length] = '\0'; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1417 | stmt->depth = strtol(conv, &chk, 10); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1418 | if (*chk || stmt->depth < -1) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1419 | dav_error_in_context(DAVQL_ERROR_INVALID_DEPTH, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1420 | _error_invalid_depth, stmt, token); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1421 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1422 | free(conv); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1423 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1424 | total_consumed += consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1425 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1426 | dav_error_in_context(DAVQL_ERROR_INVALID_DEPTH, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1427 | _error_invalid_depth, stmt, token); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1428 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1429 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1430 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1431 | dav_free_expression(depthexpr); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1432 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1433 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1434 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1435 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1436 | return total_consumed; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1437 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1438 | |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1439 | static int dav_parse_order_crit(DavQLStatement *stmt, UcxList *token, |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1440 | DavQLOrderCriterion *crit) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1441 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1442 | // RULE: (Identifier | Number), [" asc"|" desc"]; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1443 | DavQLExpression expr; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1444 | memset(&expr, 0, sizeof(DavQLExpression)); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1445 | int consumed = dav_parse_expression(stmt, token, &expr); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1446 | if (stmt->errorcode || !consumed) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1447 | return 0; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1448 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1449 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1450 | if (expr.type != DAVQL_IDENTIFIER && expr.type != DAVQL_NUMBER) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1451 | dav_error_in_context(DAVQL_ERROR_INVALID_ORDER_CRITERION, |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1452 | _error_invalid_order_criterion, stmt, token); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1453 | return 0; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1454 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1455 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1456 | dqlsec_malloc(stmt, crit->column, DavQLExpression); |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1457 | memcpy(crit->column, &expr, sizeof(DavQLExpression)); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1458 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1459 | token = ucx_list_get(token, consumed); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1460 | if (token_is(token, DAVQL_TOKEN_KEYWORD) && ( |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1461 | tokenvalue_is(token, "asc") || tokenvalue_is(token, "desc"))) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1462 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1463 | crit->descending = tokenvalue_is(token, "desc"); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1464 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1465 | return consumed+1; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1466 | } else { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1467 | crit->descending = 0; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1468 | return consumed; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1469 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1470 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1471 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1472 | static int dav_parse_orderby_clause(DavQLStatement *stmt, UcxList *token) { |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1473 | |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1474 | int total_consumed = 0, consumed; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1475 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1476 | DavQLOrderCriterion crit; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1477 | |
116
44ffe073b5e3
fixed logical expression parser
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
1478 | // RULE: OrderByCriterion, {",", OrderByCriterion}; |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1479 | do { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1480 | consumed = dav_parse_order_crit(stmt, token, &crit); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1481 | if (stmt->errorcode) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1482 | return 0; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1483 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1484 | if (!consumed) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1485 | dav_error_in_context(DAVQL_ERROR_MISSING_EXPR, _error_missing_expr, |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1486 | stmt, token); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1487 | return 0; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1488 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1489 | token = ucx_list_get(token, consumed); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1490 | total_consumed += consumed; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1491 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1492 | DavQLOrderCriterion *criterion; |
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1493 | dqlsec_malloc(stmt, criterion, DavQLOrderCriterion); |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1494 | memcpy(criterion, &crit, sizeof(DavQLOrderCriterion)); |
291
8828260d2fd8
fixes memory leak in davqlparser
Mike Becker <universe@uap-core.de>
parents:
288
diff
changeset
|
1495 | dqlsec_list_append_or_free(stmt, stmt->orderby, criterion); |
120
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1496 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1497 | if (token_is(token, DAVQL_TOKEN_COMMA)) { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1498 | total_consumed++; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1499 | token = token->next; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1500 | } else { |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1501 | consumed = 0; |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1502 | } |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1503 | } while (consumed); |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1504 | |
246c50447ebf
implemented order by parser
Mike Becker <universe@uap-core.de>
parents:
118
diff
changeset
|
1505 | return total_consumed; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1506 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1507 | |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1508 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1509 | static int dav_parse_assignments(DavQLStatement *stmt, UcxList *token) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1510 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1511 | // RULE: Assignment, {",", Assignment} |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1512 | int total_consumed = 0, consumed; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1513 | do { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1514 | // RULE: Identifier, "=", Expression |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1515 | if (token_is(token, DAVQL_TOKEN_IDENTIFIER)) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1516 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1517 | // Identifier |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1518 | DavQLField *field; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1519 | dqlsec_malloc(stmt, field, DavQLField); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1520 | field->name = token_sstr(token); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1521 | total_consumed++; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1522 | token = token->next; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1523 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1524 | // "=" |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1525 | if (!token_is(token, DAVQL_TOKEN_OPERATOR) |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1526 | || !tokenvalue_is(token, "=")) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1527 | dav_free_field(field); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1528 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1529 | dav_error_in_context(DAVQL_ERROR_MISSING_ASSIGN, |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1530 | _error_missing_assign, stmt, token); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1531 | return total_consumed; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1532 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1533 | total_consumed++; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1534 | token = token->next; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1535 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1536 | // Expression |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1537 | dqlsec_mallocz(stmt, field->expr, DavQLExpression); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1538 | consumed = dav_parse_expression(stmt, token, field->expr); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1539 | if (stmt->errorcode) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1540 | dav_free_field(field); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1541 | return total_consumed; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1542 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1543 | token = ucx_list_get(token, consumed); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1544 | total_consumed += consumed; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1545 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1546 | // Add assignment to list and check if there's another one |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1547 | dqlsec_list_append_or_free(stmt, stmt->fields, field); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1548 | consumed = token_is(token, DAVQL_TOKEN_COMMA) ? 1 : 0; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1549 | if (consumed) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1550 | token = token->next; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1551 | total_consumed++; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1552 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1553 | } else { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1554 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1555 | _error_missing_identifier, stmt, token); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1556 | return total_consumed; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1557 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1558 | } while (consumed); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1559 | |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1560 | return total_consumed; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1561 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1562 | |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1563 | static int dav_parse_path(DavQLStatement *stmt, UcxList *tokens) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1564 | if (token_is(tokens, DAVQL_TOKEN_STRING)) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1565 | stmt->path = token_sstr(tokens); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1566 | tokens = tokens->next; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1567 | return 1; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1568 | } else if (token_is(tokens, DAVQL_TOKEN_OPERATOR) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1569 | && tokenvalue_is(tokens, "/")) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1570 | stmt->path = token_sstr(tokens); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1571 | tokens = tokens->next; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1572 | int consumed = 1; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1573 | while (!token_is(tokens, DAVQL_TOKEN_KEYWORD) && |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1574 | !token_is(tokens, DAVQL_TOKEN_END)) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1575 | sstr_t toksstr = token_sstr(tokens); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1576 | stmt->path.length = toksstr.ptr-stmt->path.ptr+toksstr.length; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1577 | tokens = tokens->next; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1578 | consumed++; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1579 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1580 | return consumed; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1581 | } else if (token_is(tokens, DAVQL_TOKEN_FMTSPEC) && |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1582 | tokenvalue_is(tokens, "%s")) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1583 | stmt->path = token_sstr(tokens); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1584 | tokens = tokens->next; |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
1585 | stmt->args = ucx_list_append(stmt->args, (void*)(intptr_t)'s'); |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1586 | return 1; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1587 | } else { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1588 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1589 | _error_missing_path, stmt, tokens); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1590 | return 0; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1591 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1592 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1593 | |
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
|
1594 | /** |
127
7072a2b4ae35
renamed GET to SELECT in davql syntax
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
1595 | * Parser of a select statement. |
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
|
1596 | * @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
|
1597 | * @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
|
1598 | */ |
127
7072a2b4ae35
renamed GET to SELECT in davql syntax
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
1599 | static void dav_parse_select_statement(DavQLStatement *stmt, UcxList *tokens) { |
7072a2b4ae35
renamed GET to SELECT in davql syntax
Mike Becker <universe@uap-core.de>
parents:
125
diff
changeset
|
1600 | stmt->type = DAVQL_SELECT; |
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
|
1601 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1602 | // Consume field list |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1603 | tokens = ucx_list_get(tokens, dav_parse_fieldlist(stmt, tokens)); |
108
0199f13c7fe2
fixed parsing of binary expressions did not yield the correct type
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
1604 | if (stmt->errorcode) { |
0199f13c7fe2
fixed parsing of binary expressions did not yield the correct type
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
1605 | return; |
0199f13c7fe2
fixed parsing of binary expressions did not yield the correct type
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
1606 | } |
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
|
1607 | |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1608 | // Consume FROM keyword |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1609 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1610 | && tokenvalue_is(tokens, "from")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1611 | tokens = tokens->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1612 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1613 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1614 | _error_missing_from, stmt, tokens); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1615 | return; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1616 | } |
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
|
1617 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1618 | // Consume path |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1619 | tokens = ucx_list_get(tokens, dav_parse_path(stmt, tokens)); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1620 | if (stmt->errorcode) { |
107
a0903d2d8e3e
added format specifier parser
Mike Becker <universe@uap-core.de>
parents:
106
diff
changeset
|
1621 | return; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1622 | } |
374
38ae05d46f9a
fixes creation of davql arg list
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
365
diff
changeset
|
1623 | //dav_add_fmt_args(stmt, stmt->path); // add possible path args |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1624 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1625 | // Consume with clause (if any) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1626 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1627 | && tokenvalue_is(tokens, "with")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1628 | tokens = tokens->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1629 | tokens = ucx_list_get(tokens, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1630 | dav_parse_with_clause(stmt, tokens)); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1631 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1632 | if (stmt->errorcode) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1633 | return; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1634 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1635 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1636 | // Consume where clause (if any) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1637 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1638 | && tokenvalue_is(tokens, "where")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1639 | tokens = tokens->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1640 | tokens = ucx_list_get(tokens, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1641 | dav_parse_where_clause(stmt, tokens)); |
359
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1642 | } else if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1643 | && tokenvalue_is(tokens, "anywhere")) { |
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1644 | // useless, but the user may want to explicitly express his intent |
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1645 | tokens = tokens->next; |
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1646 | stmt->where = NULL; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1647 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1648 | if (stmt->errorcode) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1649 | return; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1650 | } |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1651 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1652 | // Consume order by clause (if any) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1653 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1654 | && tokenvalue_is(tokens, "order")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1655 | tokens = tokens->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1656 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1657 | && tokenvalue_is(tokens, "by")) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1658 | tokens = tokens->next; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1659 | tokens = ucx_list_get(tokens, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1660 | dav_parse_orderby_clause(stmt, tokens)); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1661 | } else { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1662 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1663 | _error_missing_by, stmt, tokens); |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1664 | return; |
94 | 1665 | } |
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
|
1666 | } |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1667 | if (stmt->errorcode) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1668 | return; |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1669 | } |
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
|
1670 | |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1671 | |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1672 | if (tokens) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1673 | if (token_is(tokens, DAVQL_TOKEN_INVALID)) { |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1674 | dav_error_in_context(DAVQL_ERROR_INVALID_TOKEN, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1675 | _error_invalid_token, stmt, tokens); |
117
5ffc2f23803f
fixed null pointer access on end of token stream by adding a special END token to the stream
Mike Becker <universe@uap-core.de>
parents:
116
diff
changeset
|
1676 | } else if (!token_is(tokens, DAVQL_TOKEN_END)) { |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1677 | dav_error_in_context(DAVQL_ERROR_UNEXPECTED_TOKEN, |
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1678 | _error_unexpected_token, stmt, tokens); |
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
|
1679 | } |
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
|
1680 | } |
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
|
1681 | } |
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
|
1682 | |
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
|
1683 | 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
|
1684 | 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
|
1685 | |
357
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1686 | // Consume assignments |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1687 | tokens = ucx_list_get(tokens, dav_parse_assignments(stmt, tokens)); |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1688 | if (stmt->errorcode) { |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1689 | return; |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1690 | } |
5dfbf7b45873
implements parser for Assignments (previously called SetExpressions) + improves davql debugger regarding DavQLField
Mike Becker <universe@uap-core.de>
parents:
356
diff
changeset
|
1691 | |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1692 | // Consume AT keyword |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1693 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1694 | && tokenvalue_is(tokens, "at")) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1695 | tokens = tokens->next; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1696 | } else { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1697 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1698 | _error_missing_at, stmt, tokens); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1699 | return; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1700 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1701 | |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1702 | // Consume path |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1703 | tokens = ucx_list_get(tokens, dav_parse_path(stmt, tokens)); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1704 | if (stmt->errorcode) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1705 | return; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1706 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1707 | |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1708 | // Consume with clause (if any) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1709 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1710 | && tokenvalue_is(tokens, "with")) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1711 | tokens = tokens->next; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1712 | tokens = ucx_list_get(tokens, |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1713 | dav_parse_with_clause(stmt, tokens)); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1714 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1715 | if (stmt->errorcode) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1716 | return; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1717 | } |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1718 | |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1719 | // Consume mandatory where clause (or anywhere keyword) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1720 | if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1721 | && tokenvalue_is(tokens, "where")) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1722 | tokens = tokens->next; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1723 | tokens = ucx_list_get(tokens, |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1724 | dav_parse_where_clause(stmt, tokens)); |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1725 | } else if (token_is(tokens, DAVQL_TOKEN_KEYWORD) |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1726 | && tokenvalue_is(tokens, "anywhere")) { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1727 | // no-op, but we want the user to be explicit about this |
359
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1728 | tokens = tokens->next; |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1729 | stmt->where = NULL; |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1730 | } else { |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1731 | dav_error_in_context(DAVQL_ERROR_MISSING_TOKEN, |
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1732 | _error_missing_where, stmt, tokens); |
359
bacb54502b24
davql: allow ANYWHERE keyword in SELECT statements
Mike Becker <universe@uap-core.de>
parents:
358
diff
changeset
|
1733 | return; |
358
54dbd44ac6b0
davql SET statements are now fully implemented
Mike Becker <universe@uap-core.de>
parents:
357
diff
changeset
|
1734 | } |
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
|
1735 | } |
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
|
1736 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
1737 | 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
|
1738 | 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
|
1739 | |
121
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1740 | // if we can't even get enough memory for the statement object or an error |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1741 | // message, we can simply die without returning anything |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1742 | if (!stmt) { |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1743 | return NULL; |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1744 | } |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1745 | char *oommsg = strdup(_error_out_of_memory); |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1746 | if (!oommsg) { |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1747 | free(stmt); |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1748 | return NULL; |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1749 | } |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1750 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
1751 | // 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
|
1752 | stmt->type = -1; |
85
0ab1cf261a44
improved grammar + changed depth default, type and added infinity
Mike Becker <universe@uap-core.de>
parents:
83
diff
changeset
|
1753 | stmt->depth = 1; |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
1754 | |
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
|
1755 | // 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
|
1756 | 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
|
1757 | |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1758 | if (stmt->srctext.length) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1759 | // tokenization |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1760 | UcxList* tokens = dav_parse_tokenize(stmt->srctext); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1761 | |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1762 | if (tokens) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1763 | // use first token to determine query type |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1764 | |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1765 | if (tokenvalue_is(tokens, "select")) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1766 | dav_parse_select_statement(stmt, tokens->next); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1767 | } else if (tokenvalue_is(tokens, "set")) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1768 | dav_parse_set_statement(stmt, tokens->next); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1769 | } else { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1770 | stmt->type = DAVQL_ERROR; |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1771 | stmt->errorcode = DAVQL_ERROR_INVALID; |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1772 | stmt->errormessage = strdup(_error_invalid); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1773 | } |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1774 | |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1775 | // free token data |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1776 | UCX_FOREACH(token, tokens) { |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1777 | free(token->data); |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1778 | } |
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1779 | ucx_list_free(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
|
1780 | } else { |
132
8c9b84f37af5
secured ucx_list_append calls against OOM
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
1781 | stmt->errorcode = DAVQL_ERROR_OUT_OF_MEMORY; |
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
|
1782 | } |
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
|
1783 | } 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
|
1784 | stmt->type = DAVQL_ERROR; |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
1785 | stmt->errorcode = DAVQL_ERROR_INVALID; |
106
9cec78f23cbf
started refactoring davqlparser
Mike Becker <universe@uap-core.de>
parents:
103
diff
changeset
|
1786 | stmt->errormessage = strdup(_error_invalid); |
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
|
1787 | } |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
1788 | |
122
9a016d5fa9e7
secured malloc / calloc calls
Mike Becker <universe@uap-core.de>
parents:
121
diff
changeset
|
1789 | if (stmt->errorcode == DAVQL_ERROR_OUT_OF_MEMORY) { |
121
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1790 | stmt->type = DAVQL_ERROR; |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1791 | stmt->errormessage = oommsg; |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1792 | } else { |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1793 | free(oommsg); |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1794 | } |
eea36bf5ffe2
fixed statement type for logical expressions without operator + prepared OOM handling
Mike Becker <universe@uap-core.de>
parents:
120
diff
changeset
|
1795 | |
79
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
1796 | return stmt; |
59c518ae0641
added parse function prototype + started writing a debugger
Mike Becker <universe@uap-core.de>
parents:
76
diff
changeset
|
1797 | } |
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
|
1798 | |
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
|
1799 | 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
|
1800 | 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
|
1801 | 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
|
1802 | } |
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
|
1803 | 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
|
1804 | |
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
|
1805 | 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
|
1806 | 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
|
1807 | } |
86
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
1808 | if (stmt->errormessage) { |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
1809 | free(stmt->errormessage); |
ecba8bdf9741
davql: error handling + minor grammar changes
Mike Becker <universe@uap-core.de>
parents:
85
diff
changeset
|
1810 | } |
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
|
1811 | 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
|
1812 | 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
|
1813 | } |
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
|
1814 | ucx_list_free(stmt->orderby); |
365
f04ab0420512
fixes misuse of vaarg on all platforms
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
359
diff
changeset
|
1815 | ucx_list_free(stmt->args); |
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
|
1816 | 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
|
1817 | } |