diff options
| author | Mattias Andrée <m@maandree.se> | 2026-01-03 03:48:43 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-01-03 03:48:43 +0100 |
| commit | a575c6b40aa63b64faffb8a7b9b834f52bba4f75 (patch) | |
| tree | 6773c856ffa29a74254c6a047a2bc10fc5a89c1c | |
| parent | Fix typo (diff) | |
| download | libparser-a575c6b40aa63b64faffb8a7b9b834f52bba4f75.tar.gz libparser-a575c6b40aa63b64faffb8a7b9b834f52bba4f75.tar.bz2 libparser-a575c6b40aa63b64faffb8a7b9b834f52bba4f75.tar.xz | |
Add IS_HIDDEN to make meaning clearer
Signed-off-by: Mattias Andrée <m@maandree.se>
| -rw-r--r-- | libparser.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libparser.c b/libparser.c index cb5981b..4a42c43 100644 --- a/libparser.c +++ b/libparser.c @@ -3,6 +3,8 @@ #include <stdlib.h> #include <string.h> +#define IS_HIDDEN(RULE) (!(RULE) || (RULE)[0] == '_') + struct context { const struct libparser_rule *const *rules; @@ -78,12 +80,12 @@ try_match(const char *rule, const union libparser_sentence *sentence, struct con free_unit(unit->in, ctx); goto mismatch; } - if (!unit->in->next->rule || unit->in->next->rule[0] == '_') { + if (IS_HIDDEN(unit->in->next->rule)) { unit->in->next->next = ctx->cache; ctx->cache = unit->in->next; unit->in->next = unit->in->next->in; } - if (!unit->in->rule || unit->in->rule[0] == '_') { + if (IS_HIDDEN(unit->in->rule)) { next = unit->in->next; unit->in->next = ctx->cache; ctx->cache = unit->in; @@ -105,7 +107,7 @@ try_match(const char *rule, const union libparser_sentence *sentence, struct con goto mismatch; } prone: - if (unit->in && (!unit->in->rule || unit->in->rule[0] == '_')) { + if (unit->in && IS_HIDDEN(unit->in->rule)) { unit->in->next = ctx->cache; ctx->cache = unit->in; unit->in = unit->in->in; @@ -131,7 +133,7 @@ try_match(const char *rule, const union libparser_sentence *sentence, struct con case LIBPARSER_SENTENCE_TYPE_REPEATED: head = &unit->in; while ((*head = try_match(NULL, sentence->unary.sentence, ctx))) { - if (!(*head)->rule || (*head)->rule[0] == '_') { + if (IS_HIDDEN((*head)->rule)) { (*head)->next = ctx->cache; ctx->cache = *head; *head = (*head)->in; |
