Skip whitespace and comments. Returns true if something was skipped. */
| 323 | |
| 324 | /* Skip whitespace and comments. Returns true if something was skipped. */ |
| 325 | static bool lex_skip_whitespace_comments(const char *input, int len, int *i) { |
| 326 | if (isspace((unsigned char)input[*i])) { |
| 327 | (*i)++; |
| 328 | return true; |
| 329 | } |
| 330 | if (*i + SKIP_ONE < len && input[*i] == '/' && input[*i + SKIP_ONE] == '/') { |
| 331 | while (*i < len && input[*i] != '\n') { |
| 332 | (*i)++; |
| 333 | } |
| 334 | return true; |
| 335 | } |
| 336 | /* SQL-style -- single-line comment */ |
| 337 | if (*i + SKIP_ONE < len && input[*i] == '-' && input[*i + SKIP_ONE] == '-') { |
| 338 | while (*i < len && input[*i] != '\n') { |
| 339 | (*i)++; |
| 340 | } |
| 341 | return true; |
| 342 | } |
| 343 | if (*i + SKIP_ONE < len && input[*i] == '/' && input[*i + SKIP_ONE] == '*') { |
| 344 | *i += PAIR_LEN; |
| 345 | while (*i + SKIP_ONE < len && !(input[*i] == '*' && input[*i + SKIP_ONE] == '/')) { |
| 346 | (*i)++; |
| 347 | } |
| 348 | if (*i + SKIP_ONE < len) { |
| 349 | *i += PAIR_LEN; |
| 350 | } |
| 351 | return true; |
| 352 | } |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | int cbm_lex(const char *input, cbm_lex_result_t *out) { |
| 357 | memset(out, 0, sizeof(*out)); |