Added lambda support

This commit is contained in:
Devine Lu Linvega 2024-04-10 12:30:17 -07:00
parent 19b3c03a8a
commit a966253bd7
2 changed files with 20 additions and 28 deletions

View File

@ -10,9 +10,9 @@ dest:
run: all bin/modal run: all bin/modal
@ bin/modal examples/hello.modal 2> /dev/null @ bin/modal examples/hello.modal 2> /dev/null
test: bin/modal-debug bin/modal test: bin/modal-debug bin/modal
# @ bin/modal -v @ bin/modal -v
# @ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))" @ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))"
@ bin/modal examples/test.modal @ time bin/modal examples/test.modal "(arg1) (arg2 (arg3))"
install: bin/modal install: bin/modal
cp bin/modal ~/bin/ cp bin/modal ~/bin/
uninstall: uninstall:

View File

@ -143,6 +143,18 @@ parse_frag(char *s)
return s; return s;
} }
static int
write(Rule *r, char last, char *res){
char cc, *b = r->b;
if(!*b && last == ' ') outp_--;
while((cc = *b++))
if(cc == '?')
put_reg(*b++);
else
*outp_++ = cc;
return commit_rule(r, res, 0);
}
static int static int
rewrite(void) rewrite(void)
{ {
@ -162,32 +174,12 @@ rewrite(void)
p += 2, r->a = dict_, p = parse_frag(p), r->b = dict_, p = parse_frag(p); p += 2, r->a = dict_, p = parse_frag(p), r->b = dict_, p = parse_frag(p);
p++; p++;
while((c = *p) && c <= ' ') p++; while((c = *p) && c <= ' ') p++;
if((res = match_rule(p, r)) != NULL) { if((res = match_rule(p, r)) != NULL)
char cc, *b = r->b; return write(r, last, res);
printf("LAMBDA [%s][%s] > %s\n", r->a, r->b, p);
if(!*b && last == ' ') outp_--;
while((cc = *b++)) {
if(cc == '?')
put_reg(*b++);
else
*outp_++ = cc;
}
return commit_rule(r, res, 0);
}
}
for(r = rules; r < rules_; r++) {
if((res = match_rule(p, r)) != NULL) {
char cc, *b = r->b;
if(!*b && last == ' ') outp_--;
while((cc = *b++)) {
if(cc == '?')
put_reg(*b++);
else
*outp_++ = cc;
}
return commit_rule(r, res, 0);
}
} }
for(r = rules; r < rules_; r++)
if((res = match_rule(p, r)) != NULL)
return write(r, last, res);
} }
*outp_++ = last = c; *outp_++ = last = c;
p++; p++;