summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-27 20:35:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-27 20:35:41 -0700
commit76ab4a2923919f837817e63f86dca9cd6d4ed82c (patch)
treeb9728b0b78d54737cf535ec35f6809f686c5f30f /regex.c
parent5d2ef0c1daf3d44db1acea0d201712a7b45875ea (diff)
downloadtxr-76ab4a2923919f837817e63f86dca9cd6d4ed82c.tar.gz
txr-76ab4a2923919f837817e63f86dca9cd6d4ed82c.tar.bz2
txr-76ab4a2923919f837817e63f86dca9cd6d4ed82c.zip
regex: exposing optimization pass a regex-optimize
* regex.c (regex_optimize): New static function, capturing the three optimization passes. (regex_compile): Code moved into regex_optimize. (regex_init): Remove sys:reg-optimize function. Register regex-optimize. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/regex.c b/regex.c
index 41c912a8..0033c2b9 100644
--- a/regex.c
+++ b/regex.c
@@ -2209,6 +2209,11 @@ static val regex_requires_dv(val exp)
}
}
+static val regex_optimize(val regex_sexp)
+{
+ return reg_optimize(reg_expand_nongreedy(reg_nary_to_bin(regex_sexp)));
+}
+
val regex_compile(val regex_sexp, val error_stream)
{
val regex_source = regex_sexp;
@@ -2218,7 +2223,7 @@ val regex_compile(val regex_sexp, val error_stream)
return if2(regex_sexp, regex_compile(regex_sexp, error_stream));
}
- regex_sexp = reg_optimize(reg_expand_nongreedy(reg_nary_to_bin(regex_sexp)));
+ regex_sexp = regex_optimize(regex_sexp);
if (opt_derivative_regex || regex_requires_dv(regex_sexp)) {
regex_t *regex = coerce(regex_t *, chk_malloc(sizeof *regex));
@@ -3358,7 +3363,7 @@ void regex_init(void)
reg_fun(intern(lit("reg-expand-nongreedy"), system_package),
func_n1(reg_expand_nongreedy));
- reg_fun(intern(lit("reg-optimize"), system_package), func_n1(reg_optimize));
+ reg_fun(intern(lit("regex-optimize"), user_package), func_n1(regex_optimize));
reg_fun(intern(lit("read-until-match"), user_package), func_n3o(read_until_match, 1));
reg_fun(intern(lit("scan-until-match"), user_package), func_n2(scan_until_match));
reg_fun(intern(lit("count-until-match"), user_package), func_n2(count_until_match));