| 1564 | typedef void (*cbm_error_node_fn)(TSNode node, void *arg); |
| 1565 | |
| 1566 | static void cbm_walk_error_nodes(TSNode root, const char *source, int source_len, |
| 1567 | cbm_error_node_fn fn, void *arg) { |
| 1568 | /* The thread's reusable cursor: the walk completes before anything else on |
| 1569 | * this thread can ask for it, and the callbacks never do. */ |
| 1570 | TSTreeCursor *cursor = cbm_thread_cursor(root); |
| 1571 | if (!ts_tree_cursor_goto_first_child(cursor)) { |
| 1572 | return; |
| 1573 | } |
| 1574 | int depth = 0; /* 0 while on a direct child of root */ |
| 1575 | for (;;) { |
| 1576 | TSNode c = ts_tree_cursor_current_node(cursor); |
| 1577 | bool descend = false; |
| 1578 | if (ts_node_is_missing(c) || strcmp(ts_node_type(c), "ERROR") == 0) { |
| 1579 | /* An absent final newline only means nothing was dropped. Anything |
| 1580 | * else is the top-most region; do not descend. */ |
| 1581 | if (!cbm_is_eof_terminator_miss(c, source, source_len)) { |
| 1582 | fn(c, arg); |
| 1583 | } |
| 1584 | } else if (ts_node_has_error(c)) { |
| 1585 | descend = true; |
| 1586 | } |
| 1587 | if (descend && ts_tree_cursor_goto_first_child(cursor)) { |
| 1588 | depth++; |
| 1589 | continue; |
| 1590 | } |
| 1591 | while (!ts_tree_cursor_goto_next_sibling(cursor)) { |
| 1592 | if (depth == 0) { |
| 1593 | return; |
| 1594 | } |
| 1595 | (void)ts_tree_cursor_goto_parent(cursor); |
| 1596 | depth--; |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | /* Walks to the end even after the cap is full, so `dropped` is the real number |
| 1602 | * of ranges lost rather than a lower bound. This costs little: the walk never |
no test coverage detected