chore: update c, h, md files
This commit is contained in:
+4
-2
@@ -1,6 +1,6 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_AST_H
|
||||
#define LOREG_AST_H
|
||||
#ifndef LOREX_AST_H
|
||||
#define LOREX_AST_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@@ -36,6 +36,8 @@ typedef struct {
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
bool negated;
|
||||
unsigned char bitmap[32];
|
||||
bool bitmap_valid;
|
||||
} bracket_class_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_LEXER_H
|
||||
#define LOREG_LEXER_H
|
||||
#ifndef LOREX_LEXER_H
|
||||
#define LOREX_LEXER_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_H
|
||||
#define LOREG_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define LOREG_VERSION "1.0.0"
|
||||
#define LOREG_MAX_STATES 4096
|
||||
#define LOREG_MAX_GROUPS 32
|
||||
|
||||
typedef enum {
|
||||
LOREG_OK = 0,
|
||||
LOREG_ERR_INVALID_PATTERN,
|
||||
LOREG_ERR_UNBALANCED_PAREN,
|
||||
LOREG_ERR_EMPTY_GROUP,
|
||||
LOREG_ERR_INVALID_QUANTIFIER,
|
||||
LOREG_ERR_INVALID_ESCAPE,
|
||||
LOREG_ERR_OUT_OF_MEMORY,
|
||||
LOREG_ERR_STATE_OVERFLOW
|
||||
} loreg_error_t;
|
||||
|
||||
typedef struct {
|
||||
size_t start;
|
||||
size_t end;
|
||||
bool matched;
|
||||
} loreg_group_t;
|
||||
|
||||
typedef struct {
|
||||
bool matched;
|
||||
size_t match_start;
|
||||
size_t match_end;
|
||||
loreg_group_t groups[LOREG_MAX_GROUPS];
|
||||
size_t group_count;
|
||||
} loreg_match_t;
|
||||
|
||||
typedef struct loreg_regex loreg_regex_t;
|
||||
|
||||
loreg_regex_t *loreg_compile(const char *pattern, loreg_error_t *error);
|
||||
void loreg_free(loreg_regex_t *regex);
|
||||
bool loreg_match(loreg_regex_t *regex, const char *text, loreg_match_t *result);
|
||||
bool loreg_search(loreg_regex_t *regex, const char *text, loreg_match_t *result);
|
||||
const char *loreg_error_string(loreg_error_t error);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREX_H
|
||||
#define LOREX_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define LOREX_VERSION "1.0.0"
|
||||
#define LOREX_MAX_STATES 4096
|
||||
#define LOREX_MAX_GROUPS 32
|
||||
|
||||
typedef enum {
|
||||
LOREX_OK = 0,
|
||||
LOREX_ERR_INVALID_PATTERN,
|
||||
LOREX_ERR_UNBALANCED_PAREN,
|
||||
LOREX_ERR_EMPTY_GROUP,
|
||||
LOREX_ERR_INVALID_QUANTIFIER,
|
||||
LOREX_ERR_INVALID_ESCAPE,
|
||||
LOREX_ERR_OUT_OF_MEMORY,
|
||||
LOREX_ERR_STATE_OVERFLOW
|
||||
} lorex_error_t;
|
||||
|
||||
typedef struct {
|
||||
size_t start;
|
||||
size_t end;
|
||||
bool matched;
|
||||
} lorex_group_t;
|
||||
|
||||
typedef struct {
|
||||
bool matched;
|
||||
size_t match_start;
|
||||
size_t match_end;
|
||||
lorex_group_t groups[LOREX_MAX_GROUPS];
|
||||
size_t group_count;
|
||||
} lorex_match_t;
|
||||
|
||||
typedef struct lorex_regex lorex_regex_t;
|
||||
|
||||
lorex_regex_t *lorex_compile(const char *pattern, lorex_error_t *error);
|
||||
void lorex_free(lorex_regex_t *regex);
|
||||
bool lorex_match(lorex_regex_t *regex, const char *text, lorex_match_t *result);
|
||||
bool lorex_search(lorex_regex_t *regex, const char *text, lorex_match_t *result);
|
||||
const char *lorex_error_string(lorex_error_t error);
|
||||
|
||||
#endif
|
||||
+11
-5
@@ -1,9 +1,9 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_MATCHER_H
|
||||
#define LOREG_MATCHER_H
|
||||
#ifndef LOREX_MATCHER_H
|
||||
#define LOREX_MATCHER_H
|
||||
|
||||
#include "nfa.h"
|
||||
#include "loreg.h"
|
||||
#include "lorex.h"
|
||||
|
||||
typedef struct {
|
||||
nfa_state_t **states;
|
||||
@@ -20,7 +20,13 @@ void state_set_clear(state_set_t *set);
|
||||
void state_set_add(state_set_t *set, nfa_state_t *state);
|
||||
bool state_set_contains(state_set_t *set, nfa_state_t *state);
|
||||
|
||||
bool nfa_match(nfa_t *nfa, const char *text, size_t start_pos, loreg_match_t *result);
|
||||
bool nfa_search(nfa_t *nfa, const char *text, loreg_match_t *result);
|
||||
typedef struct match_ctx match_ctx_t;
|
||||
|
||||
match_ctx_t *match_ctx_create(nfa_t *nfa);
|
||||
void match_ctx_free(match_ctx_t *ctx);
|
||||
|
||||
bool nfa_match(nfa_t *nfa, const char *text, size_t start_pos, lorex_match_t *result);
|
||||
bool nfa_match_with_ctx(nfa_t *nfa, const char *text, size_t start_pos, lorex_match_t *result, match_ctx_t *ctx);
|
||||
bool nfa_search(nfa_t *nfa, const char *text, lorex_match_t *result);
|
||||
|
||||
#endif
|
||||
|
||||
+21
-9
@@ -1,9 +1,9 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_NFA_H
|
||||
#define LOREG_NFA_H
|
||||
#ifndef LOREX_NFA_H
|
||||
#define LOREX_NFA_H
|
||||
|
||||
#include "ast.h"
|
||||
#include "loreg.h"
|
||||
#include "lorex.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -30,19 +30,19 @@ typedef enum {
|
||||
} transition_type_t;
|
||||
|
||||
typedef struct {
|
||||
transition_type_t type;
|
||||
char value;
|
||||
nfa_state_t *target;
|
||||
bracket_class_t *bracket;
|
||||
transition_type_t type;
|
||||
int group_id;
|
||||
char value;
|
||||
} transition_t;
|
||||
|
||||
struct nfa_state {
|
||||
int id;
|
||||
bool accepting;
|
||||
transition_t *transitions;
|
||||
size_t trans_count;
|
||||
size_t trans_capacity;
|
||||
int id;
|
||||
bool accepting;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -52,10 +52,22 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
nfa_state_t **states;
|
||||
nfa_state_t *start;
|
||||
char *literal_prefix;
|
||||
char *literal_suffix;
|
||||
size_t state_count;
|
||||
size_t capacity;
|
||||
nfa_state_t *start;
|
||||
size_t prefix_len;
|
||||
size_t suffix_len;
|
||||
int group_count;
|
||||
char single_first_char;
|
||||
bool anchored_start;
|
||||
bool anchored_end;
|
||||
bool first_chars_valid;
|
||||
bool is_pure_literal;
|
||||
bool has_alt_dispatch;
|
||||
unsigned char first_chars[32];
|
||||
unsigned char alt_dispatch[256];
|
||||
} nfa_t;
|
||||
|
||||
nfa_t *nfa_create(void);
|
||||
@@ -64,6 +76,6 @@ 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);
|
||||
nfa_t *nfa_from_ast(ast_node_t *ast, lorex_error_t *error);
|
||||
|
||||
#endif
|
||||
|
||||
+5
-5
@@ -1,20 +1,20 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_PARSER_H
|
||||
#define LOREG_PARSER_H
|
||||
#ifndef LOREX_PARSER_H
|
||||
#define LOREX_PARSER_H
|
||||
|
||||
#include "ast.h"
|
||||
#include "lexer.h"
|
||||
#include "loreg.h"
|
||||
#include "lorex.h"
|
||||
|
||||
typedef struct {
|
||||
lexer_t lexer;
|
||||
token_t current;
|
||||
loreg_error_t error;
|
||||
lorex_error_t error;
|
||||
int group_count;
|
||||
} parser_t;
|
||||
|
||||
void parser_init(parser_t *parser, const char *pattern);
|
||||
ast_node_t *parser_parse(parser_t *parser);
|
||||
loreg_error_t parser_get_error(parser_t *parser);
|
||||
lorex_error_t parser_get_error(parser_t *parser);
|
||||
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef LOREG_REPL_H
|
||||
#define LOREG_REPL_H
|
||||
#ifndef LOREX_REPL_H
|
||||
#define LOREX_REPL_H
|
||||
|
||||
void repl_run(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user