Disconnected rule parsing and storage

This commit is contained in:
Devine Lu Linvega 2024-04-10 11:39:15 -07:00
parent 37c92c4914
commit d255500447
1 changed files with 9 additions and 16 deletions

View File

@ -131,24 +131,15 @@ commit_rule(Rule *r, char *s, int create)
} }
static char * 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--; if(*s == '(') s++, ss--;
while((s < ss)) *dict_++ = *s++; while((s < ss)) *dict_++ = *s++;
*dict_++ = 0; *dict_++ = 0;
return s; 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++;
return s; return s;
} }
@ -158,10 +149,12 @@ rewrite(void)
char c, last = 0, *p = direction ? bank_b : bank_a; char c, last = 0, *p = direction ? bank_b : bank_a;
while((c = *p) && c <= ' ') p++; while((c = *p) && c <= ' ') p++;
while((c = *p)) { while((c = *p)) {
if(p[0] == '<' && p[1] == '>'){ if(p[0] == '<' && p[1] == '>') {
Rule *r = rules_++; Rule *r = rules_++;
r->id = rules_ - rules - 1, p += 2; 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)) { if(spacer(last)) {
Rule *r; Rule *r;