From aa89deff8d8f6ecea8c105c33f57908502a5f0d5 Mon Sep 17 00:00:00 2001 From: anon Date: Mon, 28 Aug 2023 15:43:25 +0200 Subject: [PATCH] compile fixes --- source/regex.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/source/regex.c b/source/regex.c index da047a3..57543fc 100644 --- a/source/regex.c +++ b/source/regex.c @@ -265,6 +265,20 @@ static int escape_1_to_N(const char c, compiler_state * cs) { return 0; } +static int escape_to_negative(const char c, + compiler_state * cs) { + switch (c) { + case 'D': { + const char digit_chars[] = "0123456789"; + strcpy(cs->blacklist, digit_chars); + *cs->is_negative = true; + return sizeof(digit_chars)-1; + }; + } + + return 0; +} + //static int compile_hologram(char * hologram, char * whitelist) { // if (hologram[0] == '\\') { // switch (hologram[1]) { @@ -280,14 +294,30 @@ static int escape_1_to_N(const char c, compiler_state * cs) { // } //} -static int compile_range(const char * const range, - char * whitelist, - bool * is_negative) { +static int compile_dot(compiler_state * cs) { + *cs->do_catch = true; + return true; +} + +static int compile_escape(const char c, + compiler_state * cs) { + + return escape_1_to_1(c, cs) + || escape_1_to_N(c, cs) + || escape_to_negative(c, cs) + //|| compile_hologram(*s, whitelist) + ; +} + +static int compile_range(const char * const range, + compiler_state * cs) { assert((range[0] == '[') && "Not a range."); + char * target_list = (*cs->is_negative) ? cs->blacklist : cs->whitelist; + const char * s; if (range[1] == '^') { - *is_negative = true; + *cs->is_negative = true; s = range + 2; } else { s = range + 1; @@ -494,7 +524,7 @@ static bool catch_(const regex_t * const regex, static int regex_assert(const regex_t * const regex, const char * const string, int state, - int * width) { + int width) { for (const char * s = string; *s != '\00'; s++) { // delta for (size_t i = 0; i < regex->delta_table.element_count; i++) { @@ -509,6 +539,7 @@ static int regex_assert(const regex_t * const regex, } if (catch_(regex, &state)) { + width += 1; continue; }