diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-06-27 20:49:54 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-06-27 20:49:54 -0700 |
commit | c2987ebf76b59d5d4f53b644b983bc01293b90ef (patch) | |
tree | a736f7a0a41815cce521fa0f3886075dcf67972a | |
parent | f320402186c38d570d99489ef686a155ab2b7f64 (diff) | |
download | txr-c2987ebf76b59d5d4f53b644b983bc01293b90ef.tar.gz txr-c2987ebf76b59d5d4f53b644b983bc01293b90ef.tar.bz2 txr-c2987ebf76b59d5d4f53b644b983bc01293b90ef.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.
-rw-r--r-- | regex.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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)); |