From 46c2edd4d1c2c5d0244ea8e216299d4e6db60a6b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 7 Jun 2024 14:58:50 -0400 Subject: Change parsing so that `...foo` parses as `(.)(..foo)` instead of `(..(.))(foo)` --- pattern.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pattern.c') 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; -- cgit v1.2.3