From 19b3c03a8acc86022eb028d0c9597d6e0131472e Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 10 Apr 2024 12:25:31 -0700 Subject: [PATCH] Converging lambdas and match --- src/modal.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/modal.c b/src/modal.c index 1d58ba4..9d34c3f 100644 --- a/src/modal.c +++ b/src/modal.c @@ -146,7 +146,7 @@ parse_frag(char *s) static int rewrite(void) { - char c, last = 0, *p = direction ? bank_b : bank_a; + char c, last = 0, *p = direction ? bank_b : bank_a, *res; while((c = *p) && c <= ' ') p++; while((c = *p)) { if(spacer(last)) { @@ -154,21 +154,15 @@ rewrite(void) if(p[0] == '<' && p[1] == '>') { r = rules_++; r->id = rules_ - rules - 1; - 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); return commit_rule(r, p, 1); } if(p[0] == '?' && p[1] == '(') { - char *res; - p += 2; - lambda.a = dict_, p = parse_frag(p); - lambda.b = dict_, p = parse_frag(p); + r = λ + p += 2, r->a = dict_, p = parse_frag(p), r->b = dict_, p = parse_frag(p); p++; while((c = *p) && c <= ' ') p++; - r = λ - res = match_rule(p, r); - if(res != NULL) { + 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_--; @@ -182,8 +176,7 @@ rewrite(void) } } for(r = rules; r < rules_; r++) { - char *res = match_rule(p, r); - if(res != NULL) { + if((res = match_rule(p, r)) != NULL) { char cc, *b = r->b; if(!*b && last == ' ') outp_--; while((cc = *b++)) {