diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-09-14 20:50:03 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-09-14 21:08:22 -0700 |
commit | 3775eb7b3afe49d6b39e5a907747c23de8b5f42e (patch) | |
tree | 56bfa7b4905d350529f9c3f3a83f8b96d0c36896 /regex.c | |
parent | 99a1ff71bc2a4f8a6048449836400221a22b6094 (diff) | |
download | txr-3775eb7b3afe49d6b39e5a907747c23de8b5f42e.tar.gz txr-3775eb7b3afe49d6b39e5a907747c23de8b5f42e.tar.bz2 txr-3775eb7b3afe49d6b39e5a907747c23de8b5f42e.zip |
read-until-match: fix regression.
Commit 9aa751c8a4f845ef2d2bba091c81ffeded941afd
broke things.
This fix affects the function read-until-match,
scan-until-match and count-until-match which share
implementation.
* regex.c (scan_until_common): In the REGM_MATCH_DONE
and REGM_MATCH cases, we must push the character onto
the local stack, before doing the match = stack
assignment. Otherwise, it's possible that the stack
is empty and so no match is recorded. The REGM_FAIL
case will then behave as if no match was found, consuming
a character and continuing.
* txr.1: Codify an existing behavior: only non-empty matches
for the regex are considered by read-until-match.
* tests/015/regex.tl: New file. I am amazed to discover
that we don't seem to have a test suite for regexes at all.
Putting the tests here which confirm this fix and provide
coverage for some edge cases in read-until-match.
Diffstat (limited to 'regex.c')
-rw-r--r-- | regex.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -3234,9 +3234,11 @@ static val scan_until_common(val self, val regex, val stream_in, regex_machine_reset(®m); continue; case REGM_MATCH_DONE: + push(ch, &stack); match = stack; goto out_match; case REGM_MATCH: + push(ch, &stack); match = stack; continue; case REGM_INCOMPLETE: |