56 lines
918 B
C
56 lines
918 B
C
/*
|
|
* Copyright (c) Camden Dixie O'Brien
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
#ifndef PARSER_H
|
|
#define PARSER_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_SUBEXPR,
|
|
} term_type_t;
|
|
|
|
struct _term;
|
|
typedef struct {
|
|
int len, capacity;
|
|
struct _term *contents;
|
|
} sequence_t;
|
|
|
|
typedef struct _parse_tree {
|
|
int count, capacity;
|
|
sequence_t *alternatives;
|
|
} parse_tree_t;
|
|
|
|
typedef struct _term {
|
|
quantifier_t quantifier;
|
|
term_type_t type;
|
|
union {
|
|
class_t class;
|
|
char literal;
|
|
parse_tree_t subexpr;
|
|
};
|
|
} term_t;
|
|
|
|
int parse_expr(const char *input, int rem, parse_tree_t *out);
|
|
void parse_tree_free_children(parse_tree_t *t);
|
|
|
|
#endif
|