aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2022-04-24 14:03:33 -0400
committerBruce Hill <bruce@bruce-hill.com>2022-04-24 14:03:33 -0400
commit28efb8937be16682b52a28c93df0811ac5981483 (patch)
tree0bbd8631ffe46f0bed9f2318f2a9d4d2c416b88d
parentef07c8a22ea2a5450bb3b303edbcead50b3b37ee (diff)
Simplify printing of chains
-rw-r--r--printmatch.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/printmatch.c b/printmatch.c
index 5b7e6e7..dc7ccee 100644
--- a/printmatch.c
+++ b/printmatch.c
@@ -85,10 +85,24 @@ static void _explain_matches(match_node_t *firstmatch, int depth, const char *te
// Print nonzero-width first:
for (match_node_t *m = firstmatch; m; m = m->next) {
if (RIGHT_TYPE(m)) {
- for (int i = 0; m->m->children && m->m->children[i]; i++) {
+ // Instead of printing each subchain on its own line, flatten them all out at once:
+ if (m->m->pat->type == BP_CHAIN) {
+ match_t *tmp = m->m;
+ while (tmp->pat->type == BP_CHAIN) {
+ *nextchild = new(match_node_t);
+ (*nextchild)->m = tmp->children[0];
+ nextchild = &((*nextchild)->next);
+ tmp = tmp->children[1];
+ }
*nextchild = new(match_node_t);
- (*nextchild)->m = m->m->children[i];
+ (*nextchild)->m = tmp;
nextchild = &((*nextchild)->next);
+ } else {
+ for (int i = 0; m->m->children && m->m->children[i]; i++) {
+ *nextchild = new(match_node_t);
+ (*nextchild)->m = m->m->children[i];
+ nextchild = &((*nextchild)->next);
+ }
}
if (m->m->end == m->m->start) continue;
printf("\033[%ldG\033[0;2m%s\033[0;7;%sm", 1+2*(m->m->start - text), V, color);