Move regex_t into parse.h and rename to parse_tree_t
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
#define CONSTRUCT_H
|
||||
|
||||
#include "fsa.h"
|
||||
#include "regex.h"
|
||||
#include "parse.h"
|
||||
|
||||
void construct_nfa(const regex_t *regex, fsa_t *out);
|
||||
void construct_nfa(const parse_tree_t *regex, fsa_t *out);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,10 +6,53 @@
|
||||
#ifndef PARSE_H
|
||||
#define PARSE_H
|
||||
|
||||
#include "regex.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define PARSE_FAIL (-1)
|
||||
|
||||
int parse_expr(const char *input, int rem, regex_t *out);
|
||||
typedef struct {
|
||||
bool negated;
|
||||
int count, capacity;
|
||||
char *contents;
|
||||
} parse_class_t;
|
||||
|
||||
typedef enum {
|
||||
PARSE_QUANTIFIER_NONE,
|
||||
PARSE_QUANTIFIER_STAR,
|
||||
PARSE_QUANTIFIER_PLUS,
|
||||
PARSE_QUANTIFIER_QMARK,
|
||||
} parse_quantifier_t;
|
||||
|
||||
typedef enum {
|
||||
PARSE_TERM_WILDCARD,
|
||||
PARSE_TERM_CLASS,
|
||||
PARSE_TERM_LITERAL,
|
||||
PARSE_TERM_SUBEXPR,
|
||||
PARSE_TERM_EMPTY,
|
||||
} parse_term_type_t;
|
||||
|
||||
struct _parse_term;
|
||||
typedef struct {
|
||||
int count, capacity;
|
||||
struct _parse_term *contents;
|
||||
} parse_sequence_t;
|
||||
|
||||
typedef struct {
|
||||
int count, capacity;
|
||||
parse_sequence_t *contents;
|
||||
} parse_tree_t;
|
||||
|
||||
typedef struct _parse_term {
|
||||
parse_quantifier_t quantifier;
|
||||
parse_term_type_t type;
|
||||
union {
|
||||
parse_class_t class;
|
||||
char literal;
|
||||
parse_tree_t subexpr;
|
||||
};
|
||||
} parse_term_t;
|
||||
|
||||
int parse_expr(const char *input, int rem, parse_tree_t *out);
|
||||
void parse_tree_free(const parse_tree_t *t);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
} regex_class_t;
|
||||
|
||||
typedef enum {
|
||||
REGEX_QUANTIFIER_NONE,
|
||||
REGEX_QUANTIFIER_STAR,
|
||||
REGEX_QUANTIFIER_PLUS,
|
||||
REGEX_QUANTIFIER_QMARK,
|
||||
} regex_quantifier_t;
|
||||
|
||||
typedef enum {
|
||||
REGEX_TERM_WILDCARD,
|
||||
REGEX_TERM_CLASS,
|
||||
REGEX_TERM_LITERAL,
|
||||
REGEX_TERM_SUBEXPR,
|
||||
REGEX_TERM_EMPTY,
|
||||
} regex_term_type_t;
|
||||
|
||||
struct _regex_term;
|
||||
typedef struct {
|
||||
int count, capacity;
|
||||
struct _regex_term *contents;
|
||||
} regex_sequence_t;
|
||||
|
||||
typedef struct {
|
||||
int count, capacity;
|
||||
regex_sequence_t *contents;
|
||||
} regex_t;
|
||||
|
||||
typedef struct _regex_term {
|
||||
regex_quantifier_t quantifier;
|
||||
regex_term_type_t type;
|
||||
union {
|
||||
regex_class_t class;
|
||||
char literal;
|
||||
regex_t subexpr;
|
||||
};
|
||||
} regex_term_t;
|
||||
|
||||
void regex_free(const regex_t *t);
|
||||
void regex_class_free(const regex_class_t *c);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user