aboutsummaryrefslogtreecommitdiff
path: root/sys/libsre/sre.h
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-05-31 14:53:26 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-05-31 14:53:26 -0700
commit1ef4974d3a84345c545b62ecc42c9f05bf630bf5 (patch)
treea4e3e4f2e0b8710c9af367f57cfc6c38ee8539f2 /sys/libsre/sre.h
parent3297ca7f3a3313e80e49547c857e1593286316b8 (diff)
structural regular expressions prototype
Diffstat (limited to 'sys/libsre/sre.h')
-rw-r--r--sys/libsre/sre.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/sys/libsre/sre.h b/sys/libsre/sre.h
new file mode 100644
index 0000000..a7ace1a
--- /dev/null
+++ b/sys/libsre/sre.h
@@ -0,0 +1,93 @@
+#pragma once
+
+#include <u.h>
+#include <libn.h>
+
+enum
+{
+ Toperator = RuneMask + 1,
+ Tstart = Toperator,
+ Trparen,
+ Tlparen,
+ Tor,
+ Tcat,
+ Tstar,
+ Tplus,
+ Tqmark,
+
+ Tany = Toperator << 1,
+ Tnop,
+ Tbol,
+ Teol,
+ Tcclass,
+ Tnclass,
+ Tend,
+
+ isoptor = Toperator,
+ isopand = Toperator << 1,
+};
+
+typedef struct Class Class;
+typedef struct State State;
+typedef struct Patch Patch;
+typedef struct Node Node;
+
+typedef struct Parser Parser;
+typedef struct Machine Machine;
+
+struct Class
+{
+ rune *end;
+ rune span[64];
+};
+
+struct State
+{
+ int type;
+ union {
+ State *l;
+ };
+ union {
+ State *r;
+ State *out;
+ };
+};
+
+struct Patch
+{
+ State *s;
+ Patch *link;
+};
+
+struct Node
+{
+ State *beg;
+ State *end;
+};
+
+struct Parser
+{
+ Machine *mach;
+ byte *re;
+ int wasopand : 1;
+ int *optor, optorstk[1000];
+ Node *node, nodestk[1000];
+};
+
+struct Machine
+{
+ /* memory buffers */
+ struct {
+ void *heap;
+ mem·Reallocator;
+ };
+ State *state, statestk[1000];
+
+ struct {
+ int cap;
+ int len;
+ Class *c;
+ } class;
+
+ State *entry;
+};