diff --git a/makefile b/makefile index 7b6e7ed..297bc15 100644 --- a/makefile +++ b/makefile @@ -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: diff --git a/src/modal.c b/src/modal.c index 9d34c3f..d5c3adb 100644 --- a/src/modal.c +++ b/src/modal.c @@ -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++;