From 5fa09eb636892a36c4396308d4925077cf94ee3a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 19 Sep 2021 17:38:18 -0700 Subject: Better non-verbose JSON output --- json.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'json.c') diff --git a/json.c b/json.c index 86b7da5..259e722 100644 --- a/json.c +++ b/json.c @@ -16,14 +16,6 @@ static int _json_match(const char *text, match_t *m, int comma, bool verbose); // static int _json_match(const char *text, match_t *m, int comma, bool verbose) { - if (!verbose) { - if (m->pat->type != BP_REF && m->pat->type != BP_ERROR) { - for (int i = 0; m->children && m->children[i]; i++) - comma |= _json_match(text, m->children[i], comma, verbose); - return comma; - } - } - if (comma) printf(",\n"); comma = 0; printf("{\"rule\":\""); @@ -37,7 +29,8 @@ static int _json_match(const char *text, match_t *m, int comma, bool verbose) } } printf("\",\"range\":[%ld,%ld]", m->start - text, m->end - text); - if (m->children) { + + if (m->children && (verbose || (m->pat->type != BP_REF && m->pat->type != BP_ERROR))) { printf(",\"children\":["); for (int i = 0; m->children && m->children[i]; i++) comma |= _json_match(text, m->children[i], comma, verbose); -- cgit v1.2.3