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;