The cursor sits just past VALUES. Keep the first tuple; exclude each later * literal-only tuple together with the comma before it. Runs of excluded tuples * separated only by whitespace become one exclusion. */
| 329 | * literal-only tuple together with the comma before it. Runs of excluded tuples |
| 330 | * separated only by whitespace become one exclusion. */ |
| 331 | static void sqlv_handle_values(sqlv_scan_t *sc, sqlv_ranges_t *ex) { |
| 332 | sqlv_skip_trivia(sc, NULL); |
| 333 | bool literal = false; |
| 334 | if (sqlv_at(sc, 0) != '(' || !sqlv_scan_tuple(sc, &literal)) { |
| 335 | return; |
| 336 | } |
| 337 | bool pending = false; |
| 338 | TSRange cur = {0}; |
| 339 | for (;;) { |
| 340 | bool ws_only = true; |
| 341 | sqlv_skip_trivia(sc, &ws_only); |
| 342 | if (sqlv_at(sc, 0) != ',') { |
| 343 | break; |
| 344 | } |
| 345 | uint32_t comma = sc->i; |
| 346 | TSPoint comma_pt = sqlv_point(sc); |
| 347 | sqlv_step(sc); |
| 348 | sqlv_skip_trivia(sc, NULL); |
| 349 | if (sqlv_at(sc, 0) != '(' || !sqlv_scan_tuple(sc, &literal)) { |
| 350 | break; |
| 351 | } |
| 352 | if (!literal) { |
| 353 | if (pending) { |
| 354 | sqlv_push(ex, cur); |
| 355 | } |
| 356 | pending = false; |
| 357 | continue; |
| 358 | } |
| 359 | if (!pending || !ws_only) { |
| 360 | if (pending) { |
| 361 | sqlv_push(ex, cur); |
| 362 | } |
| 363 | cur.start_byte = comma; |
| 364 | cur.start_point = comma_pt; |
| 365 | pending = true; |
| 366 | } |
| 367 | cur.end_byte = sc->i; |
| 368 | cur.end_point = sqlv_point(sc); |
| 369 | } |
| 370 | if (pending) { |
| 371 | sqlv_push(ex, cur); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | typedef struct { |
| 376 | bool started; /* a token of the current statement has been seen */ |
no test coverage detected