Create compile module combining passes together

This commit is contained in:
Camden Dixie O'Brien 2024-11-02 15:41:33 +00:00
parent 018aec5339
commit 18271a2988
3 changed files with 42 additions and 0 deletions

View File

@ -1,4 +1,5 @@
add_library(lib add_library(lib
compile.c
construct.c construct.c
convert.c convert.c
desugar.c desugar.c

28
lib/compile.c Normal file
View File

@ -0,0 +1,28 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#include "compile.h"
#include "parse.h"
#include "desugar.h"
#include "construct.h"
#include "convert.h"
bool compile(const char *regex, int len, fsa_t *dfa_out)
{
regex_t pt;
if (-1 == parse_expr(regex, len, &pt))
return false;
desugar_regex(&pt);
fsa_t nfa;
construct_nfa(&pt, &nfa);
regex_free(&pt);
convert_to_dfa(&nfa, dfa_out);
fsa_free(&nfa);
return true;
}

13
lib/include/compile.h Normal file
View File

@ -0,0 +1,13 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#ifndef COMPILE_H
#define COMPILE_H
#include "fsa.h"
bool compile(const char *regex, int len, fsa_t *dfa_out);
#endif