From 9f7faa41b5aef9239c8d3b563089b8cf5abf12bf Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 10 Apr 2024 11:13:18 -0700 Subject: [PATCH] Abstracting rule parser --- src/modal.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/modal.c b/src/modal.c index 9f6f166..1355f39 100644 --- a/src/modal.c +++ b/src/modal.c @@ -131,7 +131,7 @@ commit_rule(Rule *r, char *s, int create) } static char * -parse_rule(char *s) +parse_rule_frag(char *s) { char *ss = walk(s), *d = dict_; if(*s == '(') s++, ss--; @@ -140,17 +140,14 @@ parse_rule(char *s) return d; } -static int -add_rule(char *p) -{ +static char * +parse_rule(Rule *r, char *s){ char c; - Rule *r = rules_++; - r->id = rules_ - rules - 1, p += 2; - while((c = *p) && c <= ' ') p++; - r->a = parse_rule(p), p = walk(p); - while((c = *p) && c <= ' ') p++; - r->b = parse_rule(p), p = walk(p); - return commit_rule(r, p, 1); + while((c = *s) && c <= ' ') s++; + r->a = parse_rule_frag(s), s = walk(s); + while((c = *s) && c <= ' ') s++; + r->b = parse_rule_frag(s), s = walk(s); + return s; } static int @@ -159,8 +156,11 @@ 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] == '>') - return add_rule(p); + if(p[0] == '<' && p[1] == '>'){ + Rule *r = rules_++; + r->id = rules_ - rules - 1, p += 2; + return commit_rule(r, parse_rule(r, p), 1); + } if(spacer(last)) { Rule *r; for(r = rules; r < rules_; r++) {