diff th_regex.h @ 605:566e6ef41f9d

Initial commit of the highly experimental and unfinished regular expression parsing and matching code + unfinished test harness stuff. Not to be used.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Jan 2020 01:09:00 +0200
parents
children a0e8d9c6300b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/th_regex.h	Thu Jan 16 01:09:00 2020 +0200
@@ -0,0 +1,78 @@
+/*
+ * Simple regular expression matching functionality
+ * Programmed and designed by Matti 'ccr' Hamalainen
+ * (C) Copyright 2020 Tecnic Software productions (TNSP)
+ *
+ * Please read file 'COPYING' for information on license and distribution.
+ */
+#ifdef TH_EXPERIMENTAL_REGEX
+
+#ifndef TH_REGEX_H
+#define TH_REGEX_H
+
+#include "th_util.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//
+// Definitions
+//
+// Character type
+typedef char th_regex_char;
+
+
+struct th_regex_ctx;
+
+typedef struct
+{
+    int mode, type;
+    ssize_t repeatMin, repeatMax;
+
+    union
+    {
+        th_regex_char chr;
+
+        struct
+        {
+            size_t nchars;
+            th_regex_char *chars;
+        } list;
+
+        struct th_regex_ctx *expr;
+    } match;
+} th_regex_node;
+
+
+typedef struct th_regex_ctx
+{
+    size_t nnodes, nodessize;
+    th_regex_node *nodes;
+} th_regex_ctx;
+
+
+typedef struct
+{
+//    th_llist_t node;
+    size_t start, len;
+} th_regex_match_node;
+
+
+//
+// Functions
+//
+int th_regex_compile(th_regex_ctx **pexpr, const th_regex_char *pattern);
+void th_regex_free(th_regex_ctx *expr);
+
+int th_regex_match(const th_regex_ctx *expr, const th_regex_char *haystack,
+    BOOL *pmatched, th_regex_match_node **pmatches, const ssize_t max,
+    const int flags);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif // TH_REGEX_H
+
+#endif // TH_EXPERIMENTAL_REGEX