]> git.xolatile.top Git - public-libhl.git/commitdiff
organization, syntax fixing
authoranon <anon@anon.anon>
Thu, 24 Aug 2023 13:00:44 +0000 (15:00 +0200)
committeranon <anon@anon.anon>
Thu, 24 Aug 2023 13:00:44 +0000 (15:00 +0200)
source/regex.c

index f0a5d00b39bb5120d6c22f6b5085a45f8de94b88..af8b24ab7b6ad0f833b30b316b27a63f78fb3b67 100644 (file)
@@ -7,17 +7,7 @@
 #include <assert.h>
 #include <string.h>
 
-typedef struct {
-       int in;
-       char input;
-       int to;
-} delta_t;
-
-typedef struct {
-       int in;
-       int to;
-} offshoot_t;
-
+// ### Char tests ###
 static bool is_quantifier(const char c) {
        for (const char * s = "+*?"; *s != '\00'; s++) {
                if (*s == c) {
@@ -40,6 +30,22 @@ bool is_magic(const char c) {
 }
 
 
+
+// ### Internal Types ###
+typedef struct {
+       int in;
+       char input;
+       int to;
+} delta_t;
+
+typedef struct {
+       int in;
+       int to;
+} offshoot_t;
+
+
+
+// ### Regex creation/destruction ###
 static int escape_1_to_1(const char c, char * whitelist) {
        switch(c) {
                case 't': {
@@ -209,6 +215,19 @@ static int compile_range(const char * const     range,
        return ((s - range) + 1);
 }
 
+static bool catch_(const regex_t * const regex,
+                         int     * const state) {
+
+       for (int i = 0; i < regex->catch_table.element_size; i++){
+               const offshoot_t * const offshoot = (vector_get(&regex->catch_table, i));
+               if (offshoot->in == *state) {
+                       *state = offshoot->to;
+                       return true;
+               }
+       }
+       return false;
+}
+
 #define HALT_AND_CATCH_FIRE -1
 
 #define HOOK_ALL(from, str, to) do {                   \
@@ -270,7 +289,7 @@ regex_t * regex_compile(const char * const pattern) {
 
                EAT(1);
 
-               // Quantifier
+               // Get quantifier
                switch (*s) {
                        case '?': {
                                HOOK_ALL(0, whitelist, +1);
@@ -306,22 +325,13 @@ int regex_free(regex_t * const regex) {
        return 0;
 }
 
-bool catch_(const regex_t * const regex,
-                  int     * const state) {
 
-       for (int i = 0; i < regex->catch_table.element_size; i++){
-               const offshoot_t * const offshoot = (vector_get(&regex->catch_table, i));
-               if (offshoot->in == *state) {
-                       *state = offshoot->to;
-                       return true;
-               }
-       }
-       return false;
-}
 
-bool regex_assert(const regex_t * const  regex,
-                  const char    * const string,
-                                       int              state) {
+// ### Searching ###
+
+static bool regex_assert(const regex_t * const  regex,
+                         const char    * const string,
+                                              int              state) {
 
        for (const char * s = string; *s != '\00'; s++) {
                // delta