/* retoor <retoor@molodetz.nl> */
#ifndef LOREG_NFA_H
#define LOREG_NFA_H
#include "ast.h"
#include "loreg.h"
#include <stdbool.h>
#include <stddef.h>
#define EPSILON '\0'
#define NFA_MAX_TRANSITIONS 256
typedef struct nfa_state nfa_state_t;
typedef enum {
TRANS_CHAR,
TRANS_EPSILON,
TRANS_DOT,
TRANS_BRACKET,
TRANS_CLASS_DIGIT,
TRANS_CLASS_WORD,
TRANS_CLASS_SPACE,
TRANS_CLASS_NDIGIT,
TRANS_CLASS_NWORD,
TRANS_CLASS_NSPACE,
TRANS_GROUP_START,
TRANS_GROUP_END,
TRANS_ANCHOR_START,
TRANS_ANCHOR_END
} transition_type_t;
typedef struct {
transition_type_t type;
char value;
nfa_state_t *target;
bracket_class_t *bracket;
int group_id;
} transition_t;
struct nfa_state {
int id;
bool accepting;
transition_t *transitions;
size_t trans_count;
size_t trans_capacity;
};
typedef struct {
nfa_state_t *start;
nfa_state_t *accept;
} nfa_fragment_t;
typedef struct {
nfa_state_t **states;
size_t state_count;
size_t capacity;
nfa_state_t *start;
int group_count;
} nfa_t;
nfa_t *nfa_create(void);
void nfa_free(nfa_t *nfa);
nfa_state_t *nfa_add_state(nfa_t *nfa);
void nfa_add_transition(nfa_state_t *from, nfa_state_t *to, transition_type_t type, char value);
void nfa_add_bracket_transition(nfa_state_t *from, nfa_state_t *to, bracket_class_t *bracket);
void nfa_add_group_transition(nfa_state_t *from, nfa_state_t *to, transition_type_t type, int group_id);
nfa_t *nfa_from_ast(ast_node_t *ast, loreg_error_t *error);
#endif