From f68ce026f8cbf8bd85ffcc98beeaad75dab56c7c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 27 Jun 2021 20:49:54 -0700 Subject: 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. --- regex.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'regex.c') 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)); -- cgit v1.2.3