Limit matches queries

This commit is contained in:
Devine Lu Linvega 2024-04-24 11:12:57 -07:00
parent c63021cf03
commit 4535c11017
2 changed files with 7 additions and 6 deletions

View File

@ -8,7 +8,7 @@ all: dest
dest: dest:
@ mkdir -p bin @ mkdir -p bin
run: all bin/modal run: all bin/modal
@ bin/modal examples/hello.modal @ bin/modal -q examples/hello.modal
debug: all bin/modal-debug debug: all bin/modal-debug
@ bin/modal-debug examples/hello.modal @ bin/modal-debug examples/hello.modal
test: all bin/modal-debug bin/modal test: all bin/modal-debug bin/modal

View File

@ -105,13 +105,13 @@ write_rule(Rule *r, char *s, int create)
static int static int
apply_rule(Rule *r, char *s) apply_rule(Rule *r, char *s)
{ {
char c, *a = r->a, *regs[0x10] = {NULL}; char c, *a = r->a, *regs[0x08] = {NULL};
while((c = *a)) { /* phase: match rule */ /* phase: match rule */
while((c = *a)) {
if(c == '?') { if(c == '?') {
char *pcap = walk(s), *reg = NULL; char *pcap = walk(s), *reg = NULL;
unsigned int id = *(++a) - '0'; unsigned int id = *(++a) - '0';
if(id < r->ptr) reg = regs[id]; if((reg = regs[id])) { /* reg cmp */
if(reg) { /* reg cmp */
char *rcap = walk(reg), *pp = s; char *rcap = walk(reg), *pp = s;
while(reg < rcap || pp < pcap) while(reg < rcap || pp < pcap)
if(*reg++ != *pp++) return 0; if(*reg++ != *pp++) return 0;
@ -125,7 +125,8 @@ apply_rule(Rule *r, char *s)
if(c != *s) return 0; if(c != *s) return 0;
a++, s++; a++, s++;
} }
if(!(c = *s) || spacer(c)) { /* phase: write rule */ /* phase: write rule */
if(!(c = *s) || spacer(c)) {
char *b = r->b, *origin = dst_; char *b = r->b, *origin = dst_;
while((c = *b++)) { while((c = *b++)) {
if(c == '?') { if(c == '?') {