diff options
| -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; |
