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
@ bin/modal examples/hello.modal 2> /dev/null
test: bin/modal-debug bin/modal
# @ bin/modal -v
# @ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))"
@ bin/modal examples/test.modal
@ bin/modal -v
@ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))"
@ time bin/modal examples/test.modal "(arg1) (arg2 (arg3))"
install: bin/modal
cp bin/modal ~/bin/
uninstall:

View File

@ -143,6 +143,18 @@ parse_frag(char *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
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++;
while((c = *p) && c <= ' ') p++;
if((res = match_rule(p, r)) != NULL) {
char cc, *b = r->b;
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);
}
if((res = match_rule(p, r)) != NULL)
return write(r, last, res);
}
for(r = rules; r < rules_; r++)
if((res = match_rule(p, r)) != NULL)
return write(r, last, res);
}
*outp_++ = last = c;
p++;