From 007cddc2928e9cf12178c0223846146aef4c6c24 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 27 Oct 2024 01:24:21 +0100 Subject: [PATCH] Add some runtime assertions for state zero being final I'm using this invariant to save work finding the final state so it makes sense to test it. --- lib/construct.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/construct.c b/lib/construct.c index e54bcc6..62bf32d 100644 --- a/lib/construct.c +++ b/lib/construct.c @@ -33,6 +33,8 @@ static void construct_term(const regex_term_t *term, fsa_t *out) case REGEX_TERM_CLASS: assert(false); } + + assert(out->states[0].final); } static void concat_fsas(fsa_t *base, const fsa_t *other) @@ -65,6 +67,8 @@ static void concat_fsas(fsa_t *base, const fsa_t *other) free(other->states[0].rules); free(other->states); + + assert(base->states[0].final); } static void construct_sequence(const regex_sequence_t *seq, fsa_t *out) @@ -77,6 +81,8 @@ static void construct_sequence(const regex_sequence_t *seq, fsa_t *out) construct_term(&seq->contents[i], &term_fsa); concat_fsas(out, &term_fsa); } + + assert(out->states[0].final); } void construct(const regex_t *regex, fsa_t *out)