summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-27 20:49:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-27 20:49:54 -0700
commitf68ce026f8cbf8bd85ffcc98beeaad75dab56c7c (patch)
treea736f7a0a41815cce521fa0f3886075dcf67972a /regex.c
parent76ab4a2923919f837817e63f86dca9cd6d4ed82c (diff)
downloadtxr-f68ce026f8cbf8bd85ffcc98beeaad75dab56c7c.tar.gz
txr-f68ce026f8cbf8bd85ffcc98beeaad75dab56c7c.tar.bz2
txr-f68ce026f8cbf8bd85ffcc98beeaad75dab56c7c.zip
regex: bugfix: print/read consistency of n-ary ops.
The regex-compile function accepts syntax in which certain operators like (or ...) can be n-ary. This representation is converted to the strictly binary form that is understood by the compiler internals (and which regex-parse outputs), as well as the regex printer. Unfrotunately, regex-compile is attaching the original form with the n-ary operators to the regex object, and the printer does not reat this; it renders the syntax with portions missing. It needs the binary form. * regex.c (regex_compile): Capture the intermediate result from calling reg_nary_to_bin, and use that as regex_source. The pass that through the remaining two optimization passes to obtain regex_sexp which is compiled.
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/regex.c b/regex.c
index 0033c2b9..21e5cb7e 100644
--- a/regex.c
+++ b/regex.c
@@ -2216,14 +2216,16 @@ static val regex_optimize(val regex_sexp)
val regex_compile(val regex_sexp, val error_stream)
{
- val regex_source = regex_sexp;
+ val regex_source;
if (stringp(regex_sexp)) {
regex_sexp = regex_parse(regex_sexp, default_null_arg(error_stream));
return if2(regex_sexp, regex_compile(regex_sexp, error_stream));
}
- regex_sexp = regex_optimize(regex_sexp);
+ regex_source = reg_nary_to_bin(regex_sexp);
+
+ regex_sexp = reg_optimize(reg_expand_nongreedy(regex_source));
if (opt_derivative_regex || regex_requires_dv(regex_sexp)) {
regex_t *regex = coerce(regex_t *, chk_malloc(sizeof *regex));