diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 22f28b1..32729b1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(lib + compile.c construct.c convert.c desugar.c diff --git a/lib/compile.c b/lib/compile.c new file mode 100644 index 0000000..b81ded9 --- /dev/null +++ b/lib/compile.c @@ -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; +} diff --git a/lib/include/compile.h b/lib/include/compile.h new file mode 100644 index 0000000..d9ff077 --- /dev/null +++ b/lib/include/compile.h @@ -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