]> git.xolatile.top Git - public-libhl.git/commitdiff
compile fixes
authoranon <anon@anon.anon>
Mon, 28 Aug 2023 13:43:25 +0000 (15:43 +0200)
committeranon <anon@anon.anon>
Mon, 28 Aug 2023 13:44:14 +0000 (15:44 +0200)
source/regex.c

index da047a393fff2a1f966034d10f6d675c759aa17d..57543fc309894e3f54ec33a5d02915b1b11702ef 100644 (file)
@@ -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;
                }