From 4322d96ee236c20be5414a8583b21c24a4c97058 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 20 Apr 2024 18:56:04 -0700 Subject: [PATCH] Improved native substring capabilities --- examples/tests.modal | 4 +++- src/modal.c | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/tests.modal b/examples/tests.modal index d2a891d..e4f1f28 100644 --- a/examples/tests.modal +++ b/examples/tests.modal @@ -39,11 +39,13 @@ compare (abc abc abc) (#t) test replace-empty abc = ?y test -?(?-) (Connecting register output) +?(?-) (Substring registers) <> (connect ?x ?y ?z) (?x-?y?z) +<> (prefix-?x) (?x-suffix) connect foo bar baz = foo-barbaz test +prefix-anything = anything-suffix test ?(?-) (Inline register) diff --git a/src/modal.c b/src/modal.c index 77f8666..28b70a5 100644 --- a/src/modal.c +++ b/src/modal.c @@ -97,20 +97,22 @@ static char * match_rule(Rule *r, char *p) { int i; - char c, last = 0, *a = r->a, *b = p; + char c, *a = r->a, *b = p; if(rmax) { for(i = rmin; i <= rmax; i++) regs[i] = 0; rmin = 0xff, rmax = 0x00; } while((c = *a)) { - if(c == '?' && spacer(last) && spacer(a[2])) { + if(c == '?') { if(!set_reg(*(++a), b)) return NULL; a++, b = walk(b); + if(!spacer(*a)) + while((c = *a) && !spacer(c)) a++; continue; } if(c != *b) return NULL; - a++, b++, last = c; + a++, b++; } c = *b; return spacer(c) ? b : NULL;