Define regex_t data structure and write build script

This commit is contained in:
2024-10-25 13:30:33 +01:00
parent 8f4fe21bcf
commit 27b4b28fba
3 changed files with 108 additions and 0 deletions

54
lib/regex.h Normal file
View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#ifndef REGEX_H
#define REGEX_H
#include <stdbool.h>
typedef struct {
bool negated;
int count, capacity;
char *contents;
} class_t;
typedef enum {
QUANTIFIER_NONE,
QUANTIFIER_ZERO_OR_MORE,
QUANTIFIER_ONE_OR_MORE,
QUANTIFIER_ZERO_OR_ONE,
} quantifier_t;
typedef enum {
TERM_TYPE_WILDCARD,
TERM_TYPE_CLASS,
TERM_TYPE_LITERAL,
TERM_TYPE_REGEX,
} term_type_t;
struct _term;
typedef struct {
int len, capacity;
struct _term *contents;
} sequence_t;
typedef struct _regex {
sequence_t sequence;
struct _regex *alternative;
} regex_t;
typedef struct _term {
quantifier_t quantifier;
term_type_t type;
union {
class_t class;
char literal;
regex_t regex;
};
} term_t;
void regex_free_children(regex_t *r);
#endif