From d2555004472c2acec3e0d84505f3baed91db3e60 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 10 Apr 2024 11:39:15 -0700 Subject: [PATCH] Disconnected rule parsing and storage --- src/modal.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/modal.c b/src/modal.c index a9596e7..71276c2 100644 --- a/src/modal.c +++ b/src/modal.c @@ -131,24 +131,15 @@ commit_rule(Rule *r, char *s, int create) } static char * -parse_rule_frag(char *s) +parse_frag(char *s) { - char *ss = walk(s); + char c, *ss; + while((c = *s) && c <= ' ') s++; + ss = walk(s); if(*s == '(') s++, ss--; while((s < ss)) *dict_++ = *s++; *dict_++ = 0; - return s; -} - -static char * -parse_rule(Rule *r, char *s){ - char c; - while((c = *s) && c <= ' ') s++; - r->a = dict_; - s = parse_rule_frag(s), s++; - while((c = *s) && c <= ' ') s++; - r->b = dict_; - s = parse_rule_frag(s), s++; + s++; return s; } @@ -158,10 +149,12 @@ rewrite(void) char c, last = 0, *p = direction ? bank_b : bank_a; while((c = *p) && c <= ' ') p++; while((c = *p)) { - if(p[0] == '<' && p[1] == '>'){ + if(p[0] == '<' && p[1] == '>') { Rule *r = rules_++; r->id = rules_ - rules - 1, p += 2; - return commit_rule(r, parse_rule(r, p), 1); + r->a = dict_, p = parse_frag(p); + r->b = dict_, p = parse_frag(p); + return commit_rule(r, p, 1); } if(spacer(last)) { Rule *r;