#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) {
}
+
+// ### 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': {
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(®ex->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 { \
EAT(1);
- // Quantifier
+ // Get quantifier
switch (*s) {
case '?': {
HOOK_ALL(0, whitelist, +1);
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(®ex->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