libidav/davqlparser.h

changeset 101
95a215337b53
parent 98
237844f263b4
child 102
e9ae1318a559
equal deleted inserted replaced
100:f4127c4d1018 101:95a215337b53
44 44
45 /** 45 /**
46 * Enumeration of possible expression types. 46 * Enumeration of possible expression types.
47 */ 47 */
48 typedef enum { 48 typedef enum {
49 DAVQL_LITERAL, DAVQL_IDENTIFIER, 49 DAVQL_UNDEFINED_TYP,
50 DAVQL_NUMBER, DAVQL_STRING, DAVQL_TIMESTAMP, DAVQL_IDENTIFIER,
50 DAVQL_UNARY, DAVQL_BINARY, DAVQL_LOGICAL, DAVQL_FUNCCALL 51 DAVQL_UNARY, DAVQL_BINARY, DAVQL_LOGICAL, DAVQL_FUNCCALL
51 } davqlexprtype_t; 52 } davqlexprtype_t;
52 53
53 /** 54 /**
54 * Enumeration of possible expression operators. 55 * Enumeration of possible expression operators.
55 */ 56 */
56 typedef enum { 57 typedef enum {
57 DAVQL_NOOP, 58 DAVQL_NOOP, DAVQL_CALL, DAVQL_ARGLIST, // internal representations
58 DAVQL_ADD, DAVQL_SUB, DAVQL_MUL, DAVQL_DIV, 59 DAVQL_ADD, DAVQL_SUB, DAVQL_MUL, DAVQL_DIV,
59 DAVQL_AND, DAVQL_OR, DAVQL_XOR, DAVQL_NEG, 60 DAVQL_AND, DAVQL_OR, DAVQL_XOR, DAVQL_NEG, // airthmetic
60 DAVQL_NOT, DAVQL_LAND, DAVQL_LOR, DAVQL_LXOR, 61 DAVQL_NOT, DAVQL_LAND, DAVQL_LOR, DAVQL_LXOR, // logical
61 DAVQL_EQ, DAVQL_NEQ, DAVQL_LT, DAVQL_GT, DAVQL_LE, DAVQL_GE, 62 DAVQL_EQ, DAVQL_NEQ, DAVQL_LT, DAVQL_GT, DAVQL_LE, DAVQL_GE,
62 DAVQL_LIKE, DAVQL_UNLIKE 63 DAVQL_LIKE, DAVQL_UNLIKE // comparisons
63 } davqloperator_t; 64 } davqloperator_t;
64 65
65 /** 66 /**
66 * An expression within a DAVQL query. 67 * An expression within a DAVQL query.
67 */ 68 */
80 * The expression type. 81 * The expression type.
81 */ 82 */
82 davqlexprtype_t type; 83 davqlexprtype_t type;
83 /** 84 /**
84 * Operator. 85 * Operator.
85 *
86 */ 86 */
87 davqloperator_t op; 87 davqloperator_t op;
88 /** 88 /**
89 * Left or single operand. 89 * Left or single operand.
90 * <code>NULL</code> for literals or identifiers. 90 * <code>NULL</code> for literals or identifiers.
95 * <code>NULL</code> for literals, identifiers or unary expressions. 95 * <code>NULL</code> for literals, identifiers or unary expressions.
96 */ 96 */
97 DavQLExpression *right; 97 DavQLExpression *right;
98 }; 98 };
99 99
100 /**
101 * A tuple representing an order criterion.
102 */
103 typedef struct {
104 /**
105 * The column.
106 */
107 DavQLExpression *column;
108 /**
109 * True, if the result shall be sorted descending, false otherwise.
110 * Default is false (ascending).
111 */
112 _Bool descending;
113 } DavQLOrderCriterion;
114
115 /**
116 * A tuple representing a field.
117 */
118 typedef struct {
119 /**
120 * The field name.
121 * <ul>
122 * <li>GET: the identifier or an alias name</li>
123 * <li>SET: the identifier</li>
124 * </ul>
125 */
126 sstr_t name;
127 /**
128 * The field expression.
129 * <ul>
130 * <li>GET: the queried property (identifier) or an expression</li>
131 * <li>SET: the expression for the value to be set</li>
132 * </ul>
133 */
134 DavQLExpression *expr;
135 } DavQLField;
100 136
101 /** 137 /**
102 * Query statement object. 138 * Query statement object.
103 * Contains the binary information about the parsed query. 139 * Contains the binary information about the parsed query.
104 * 140 *
108 * Expression = Expression, BinaryOperator, Expression 144 * Expression = Expression, BinaryOperator, Expression
109 * | UnaryOperator, Expression 145 * | UnaryOperator, Expression
110 * | FunctionCall | Identifier | Literal 146 * | FunctionCall | Identifier | Literal
111 * | "(", Expression, ")"; 147 * | "(", Expression, ")";
112 * 148 *
113 * FunctionCall = Identifier, "(", Expression, ")"; 149 * FunctionCall = Identifier, "(", ArgumentList, ")";
150 * ArgumentList = Expression, {",", Expression};
114 * Identifier = IdentifierChar - ?Digit?, {IdentifierChar} 151 * Identifier = IdentifierChar - ?Digit?, {IdentifierChar}
115 * | "`", ?Character?, {?Character?}, "`"; 152 * | "`", ?Character? - "`", {?Character? - "`"}, "`";
116 * IdentifierChar = ?Character - (" "|",")?; 153 * IdentifierChar = ?Character? - (" "|",");
117 * Literal = Number | String; 154 * Literal = Number | String | Timestamp;
118 * Number = ?Digit?, {?Digit?} | "%d"; 155 * Number = ?Digit?, {?Digit?} | "%d";
119 * String = "'", {?Character - "'"? | "'''"} , "'"; 156 * String = "'", {?Character? - "'" | "'''"} , "'" | "%s";
157 * Timestamp = "%t"; // TODO: maybe introduce a real literal
120 * 158 *
121 * LogicalExpression = LogicalExpression, LogicalOperator, LogicalExpression 159 * LogicalExpression = LogicalExpression, LogicalOperator, LogicalExpression
122 * | "not ", LogicalExpression 160 * | "not ", LogicalExpression
123 * | Expression, Comparison, Expression 161 * | Expression, Comparison, Expression
124 * | Expression, (" like " | " unlike "), String 162 * | Expression, (" like " | " unlike "), String
127 * UnaryOperator = "-" | "~"; 165 * UnaryOperator = "-" | "~";
128 * BinaryOperator = "+" | "-" | "*" | "/" | "&" | "|" | "^"; 166 * BinaryOperator = "+" | "-" | "*" | "/" | "&" | "|" | "^";
129 * LogicalOperator = " and " | " or " | " xor "; 167 * LogicalOperator = " and " | " or " | " xor ";
130 * Comparison = | "=" | "<" | ">" | "<=" | ">=" | "!="; 168 * Comparison = | "=" | "<" | ">" | "<=" | ">=" | "!=";
131 * 169 *
132 * FieldExpressions = "*", {",", Expression, " as ", String} 170 * FieldExpressions = "*", {",", Expression, " as ", Identifier}
133 * | FieldExpression, {",", FieldExpression} 171 * | FieldExpression, {",", FieldExpression}
134 * | "-"; 172 * | "-";
135 * FieldExpression = Identifier 173 * FieldExpression = Identifier
136 * | Expression, " as ", String; 174 * | Expression, " as ", Identifier;
137 * SetExpressions = SetExpression, {",", {SetExpressions}; 175 * SetExpressions = SetExpression, {",", SetExpressions};
138 * SetExpression = Identifier, "=", Expression; 176 * SetExpression = Identifier, "=", Expression;
139 * 177 *
178 * Path = "%s"
179 * | "/", {?Character? - " "}
180 * | "'/", {?Character?}, "'";
181 *
140 * WithClause = "depth", "=", (Number | "infinity"); 182 * WithClause = "depth", "=", (Number | "infinity");
183 *
184 * OrderByClause = OrderByCriterion, {",", OrderByCriterion};
185 * OrderByCriterion = (Identifier | Number), [" asc"|" desc"];
141 * 186 *
142 * </pre> 187 * </pre>
143 * 188 *
144 * Note: mandatory spaces are part of the grammar. But you may also insert an 189 * Note: mandatory spaces are part of the grammar. But you may also insert an
145 * arbitrary amount of optional spaces between two symbols if they are not part 190 * arbitrary amount of optional spaces between two symbols if they are not part
146 * of an literal or identifier. 191 * of an literal or identifier.
147 * 192 *
148 * <b>GET:</b> 193 * <b>GET:</b>
149 * <pre> 194 * <pre>
150 * GetStatement = "get ", FieldExpressions, 195 * GetStatement = "get ", FieldExpressions,
151 * " from ", Identifier, 196 * " from ", Path,
197 * [" with ", WithClause],
152 * [" where ", LogicalExpression], 198 * [" where ", LogicalExpression],
153 * [" with ", WithClause]; 199 * [" order by ", OrderByClause];
154 * </pre> 200 * </pre>
155 * 201 *
156 * <b>SET:</b> 202 * <b>SET:</b>
157 * <pre> 203 * <pre>
158 * "set ",SetExpressions, 204 * "set ",SetExpressions,
159 * " at ", Identifier, 205 * " at ", Path,
160 * (" where ", LogicalExpression) | " anywhere", 206 * [" with ", WithClause],
161 * [" with ", WithClause]; 207 * (" where ", LogicalExpression) | " anywhere";
162 * </pre> 208 * </pre>
163 * 209 *
164 */ 210 */
165 typedef struct { 211 typedef struct {
166 /** 212 /**
178 /** 224 /**
179 * Error message, if any error occurred. 225 * Error message, if any error occurred.
180 */ 226 */
181 char* errormessage; 227 char* errormessage;
182 /** 228 /**
183 * The list of field expressions. 229 * The list of DavQLFields.
184 */ 230 */
185 UcxList* fields; 231 UcxList* fields;
186 /**
187 * The list of DavQLExpressions for the new DAV property values.
188 * This is <code>NULL</code> for GET queries.
189 */
190 UcxList* setvalues;
191 /** 232 /**
192 * A string that denotes the queried path. 233 * A string that denotes the queried path.
193 */ 234 */
194 sstr_t path; 235 sstr_t path;
195 /** 236 /**
196 * Logical expression for selection. 237 * Logical expression for selection.
197 * <code>NULL</code>, if there is no where clause. 238 * <code>NULL</code>, if there is no where clause.
198 */ 239 */
199 DavQLExpression* where; 240 DavQLExpression* where;
200 /** 241 /**
242 * The list of DavQLOrderCriterions.
243 * This is <code>NULL</code> for SET queries and may be <code>NULL</code>
244 * if the result doesn't need to be sorted.
245 */
246 UcxList* orderby;
247 /**
201 * The recursion depth for the statement. 248 * The recursion depth for the statement.
202 * Defaults to 1. 249 * Defaults to 1.
250 * Magic numbers are DAV_DEPTH_INFINITY for infinity and
251 * DAV_DEPTH_PLACEHOLDER for a placeholder.
203 */ 252 */
204 int depth; 253 int depth;
205 } DavQLStatement; 254 } DavQLStatement;
206 255
207 /** Infinity recursion depth for a DavQLStatement. */ 256 /** Infinity recursion depth for a DavQLStatement. */
208 #define DAV_DEPTH_INFINITY -1 257 #define DAV_DEPTH_INFINITY -1
258
259 /** Depth needs to be specified at runtime. */
260 #define DAV_DEPTH_PLACEHOLDER -2
261
262 /** Invalid path. */
263 #define DAVQL_ERROR_INVALID_PATH 1
264
265 /** Expected an identifier, but found something else. */
266 #define DAVQL_ERROR_IDENTIFIER_EXPECTED 10
267
268 /** Expected an identifier or literal, but found something else. */
269 #define DAVQL_ERROR_IDORLIT_EXPECTED 11
270
271 /** Expected an identifier or number, but found something else. */
272 #define DAVQL_ERROR_IDORNUM_EXPECTED 12
273
274 /** Expected an identifier or string, but found something else. */
275 #define DAVQL_ERROR_IDORSTR_EXPECTED 13
276
277 /** Expected an identifier or timestamp, but found something else. */
278 #define DAVQL_ERROR_IDORTS_EXPECTED 14
279
280 /** The with-clause contains an unknown attribute. */
281 #define DAVQL_ERROR_UNKNOWN_ATTRIBUTE 20
282
283 /** Depth must be greater than zero or infinity. */
284 #define DAVQL_ERROR_INVALID_DEPTH 21
285
286 /** The with-clause contains an attribute more than once. */
287 #define DAVQL_ERROR_DUPLICATED_ATTRIBUTE 29
288
289 /** The format specifier is missing. */
290 #define DAVQL_ERROR_MISSING_FMTSPEC 30
291
292 /** The format specifier is unknown. */
293 #define DAVQL_ERROR_UNKNOWN_FMTSPEC 31
294
295 /** The format specifier is invalid. */
296 #define DAVQL_ERROR_INVALID_FMTSPEC 39
209 297
210 /** A quote symbol (' or `) is missing. */ 298 /** A quote symbol (' or `) is missing. */
211 #define DAVQL_ERROR_MISSING_QUOTE 50 299 #define DAVQL_ERROR_MISSING_QUOTE 50
212 300
213 /** No more tokens to parse, but the parser expected more. */ 301 /** No more tokens to parse, but the parser expected more. */

mercurial