regex-engine/lib/regex.h

55 lines
826 B
C

/*
* 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