244 |
244 |
245 #define _unexpected_end_msg "unexpected end of statement" |
245 #define _unexpected_end_msg "unexpected end of statement" |
246 #define _invalid_msg "invalid statement" |
246 #define _invalid_msg "invalid statement" |
247 #define _unexpected_token "unexpected token (%.*s [->]%.*s %.*s)" |
247 #define _unexpected_token "unexpected token (%.*s [->]%.*s %.*s)" |
248 #define _expected_token "expected token '%s' before '%.*s'" |
248 #define _expected_token "expected token '%s' before '%.*s'" |
249 #define _expected_by "expected by after order (order [->]%.*s)" |
249 #define _expected_by "expected 'by' after 'order' (order [->]%.*s)" |
250 #define _missing_quote "missing closing quote symbol (%.*s)" |
250 #define _missing_quote "missing closing quote symbol (%.*s)" |
251 #define _parser_state "parser reached invalid state" |
251 #define _parser_state "parser reached invalid state" |
252 #define _unknown_attribute "unknown attribute '%.*s'" |
252 #define _unknown_attribute "unknown attribute '%.*s'" |
253 #define _duplicated_attribute "duplicated attribute '%.*s'" |
253 #define _duplicated_attribute "duplicated attribute '%.*s'" |
254 #define _invalid_depth "invalid depth" |
254 #define _invalid_depth "invalid depth" |
255 #define _identifier_expected "identifier expected, but found: %.*s" |
255 #define _identifier_expected "identifier expected, but found: %.*s" |
256 |
256 |
|
257 static const char *special_token_symbols = ",()+-*/&|^~=!<>"; |
|
258 |
257 static UcxList* dav_parse_tokenize(sstr_t src) { |
259 static UcxList* dav_parse_tokenize(sstr_t src) { |
258 UcxList *tokens = NULL; |
260 UcxList *tokens = NULL; |
259 |
261 |
260 // Delimiters: whitespace and dead whitespace around commas |
|
261 sstr_t *token = NULL; |
262 sstr_t *token = NULL; |
262 char insequence = '\0'; |
263 char insequence = '\0'; |
263 for (size_t i = 0 ; i < src.length ; i++) { |
264 for (size_t i = 0 ; i < src.length ; i++) { |
264 // quoted strings / identifiers are a single token |
265 // quoted strings / identifiers are a single token |
265 if (src.ptr[i] == '\'' || src.ptr[i] == '`') { |
266 if (src.ptr[i] == '\'' || src.ptr[i] == '`') { |
288 // add token before spaces to list (if any) |
289 // add token before spaces to list (if any) |
289 if (token) { |
290 if (token) { |
290 tokens = ucx_list_append(tokens, token); |
291 tokens = ucx_list_append(tokens, token); |
291 token = NULL; |
292 token = NULL; |
292 } |
293 } |
293 } else if (src.ptr[i] == ',') { |
294 } else if (strchr(special_token_symbols, src.ptr[i])) { |
294 // add token before comma to list (if any) |
295 // add token before special symbol to list (if any) |
295 if (token) { |
296 if (token) { |
296 tokens = ucx_list_append(tokens, token); |
297 tokens = ucx_list_append(tokens, token); |
297 token = NULL; |
298 token = NULL; |
298 } |
299 } |
299 // add comma as token to list |
300 // add special symbol as single token to list |
300 token = malloc(sizeof(sstr_t)); |
301 token = malloc(sizeof(sstr_t)); |
301 token->ptr = src.ptr + i; |
302 token->ptr = src.ptr + i; |
302 token->length = 1; |
303 token->length = 1; |
303 tokens = ucx_list_append(tokens, token); |
304 tokens = ucx_list_append(tokens, token); |
304 // set tokenizer ready to read more tokens |
305 // set tokenizer ready to read more tokens |