From ea9935babbe977bf5d980d06fc84f30523b3740a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 12 Apr 2024 10:30:59 -0700 Subject: [PATCH] Allow for empty right-hand side rules --- src/modal.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/modal.c b/src/modal.c index cf5c211..76eaab9 100644 --- a/src/modal.c +++ b/src/modal.c @@ -19,7 +19,7 @@ walk(char *s) { char c; int depth = 0; - if(s[0] == '(') { + if(*s == '(') { while((c = *s++)) { if(c == '(') depth++; if(c == ')') --depth; @@ -36,7 +36,7 @@ plode(char *s) int i, depth = 0; char c, *ss; /* implode */ - if(s[0] == '(') { + if(*s == '(') { ss = walk(s); while(s < ss && (c = *s++)) if(!spacer(c)) *outp_++ = c; @@ -149,20 +149,22 @@ parse_frag(char *s) { char c, *ss; while((c = *s) && c <= ' ') s++; - ss = walk(s); - if(*s == '(') s++, ss--; - while(s < ss) *dict_++ = *s++; + if(*s != ')' && *s != '<' && s[1] != '>') { + ss = walk(s); + if(*s == '(') s++, ss--; + while(s < ss) *dict_++ = *s++; + s++; + } *dict_++ = 0; - s++; return s; } static char * create_rule(Rule *r, int id, char *s) { - char c; r->id = id, s += 2; - r->a = dict_, s = parse_frag(s), r->b = dict_, s = parse_frag(s); + r->a = dict_, s = parse_frag(s); + r->b = dict_, s = parse_frag(s); return s; } @@ -174,13 +176,13 @@ rewrite(void) while((c = *s)) { if(spacer(last)) { Rule *r; - if(s[0] == '<' && s[1] == '>') { + if(*s == '<' && s[1] == '>') { r = rules_++; s = create_rule(r, rules_ - rules - 1, s); while((c = *s) && c <= ' ') s++; return commit_rule(r, s, 1); } - if(s[0] == '?' && s[1] == '(') { + if(*s == '?' && s[1] == '(') { r = &lambda, cap = walk(s + 1); create_rule(&lambda, -1, s), s = cap; while((c = *s) && c <= ' ') s++;