summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-29 06:46:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-29 06:46:07 -0700
commit8843aff1cf55256596bce77e90532b1115e8547e (patch)
treed4adbd8fd2631869e2dab7a5b8b209fd5a134215 /regex.c
parentd20e981aeec0413c01421920d80f5b077ba95769 (diff)
downloadtxr-8843aff1cf55256596bce77e90532b1115e8547e.tar.gz
txr-8843aff1cf55256596bce77e90532b1115e8547e.tar.bz2
txr-8843aff1cf55256596bce77e90532b1115e8547e.zip
Additional reductions for and.
* regex.c (reg_optimize): If the empty regex is and-ed with another regex, that other regex must be nullable, otherwise the and matches nothing. This is captured in some new reductions for the and operator.
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/regex.c b/regex.c
index 3943d93a..823f0c4e 100644
--- a/regex.c
+++ b/regex.c
@@ -1945,6 +1945,12 @@ static val reg_optimize(val exp)
if (arg1 == t || arg2 == t)
return t;
+ if (arg1 == nil)
+ return null(reg_nullable(arg2));
+
+ if (arg2 == nil)
+ return null(reg_nullable(arg1));
+
if (reg_matches_all(arg1))
return arg2;