aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-06-07 14:58:50 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-06-07 14:58:50 -0400
commit46c2edd4d1c2c5d0244ea8e216299d4e6db60a6b (patch)
tree085927ea67cb173c5ec1afba859eb2e8490d9df9
parent31e414af503cbbc29f40ab6127073be939ffada1 (diff)
Change parsing so that `...foo` parses as `(.)(..foo)` instead of
`(..(.))(foo)`
-rw-r--r--pattern.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/pattern.c b/pattern.c
index a3d66e6..aa7850b 100644
--- a/pattern.c
+++ b/pattern.c
@@ -224,7 +224,11 @@ static bp_pat_t *_bp_simplepattern(const char *str, const char *end, bool inside
switch (c) {
// Any char (dot)
case '.': {
- if (*str == '.') { // ".."
+ // As a special case, 3+ dots is parsed as a series of "any char" followed by a single "upto"
+ // In other words, `...foo` parses as `(.)(..foo)` instead of `(..(.)) (foo)`
+ // This is so that `...` can mean "at least one character upto" instead of "upto any character",
+ // which is tautologically the same as matching any single character.
+ if (*str == '.' && (str+1 >= end || str[1] != '.')) { // ".."
str = next_char(str, end);
enum bp_pattype_e type = BP_UPTO;
bp_pat_t *extra_arg = NULL;