From bcbfe0278376920259984e814f2ffe7b069aa3f7 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 24 Apr 2024 13:45:08 -0700 Subject: [PATCH] Progress in merging parsers --- src/modal.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/modal.c b/src/modal.c index 32c3843..740cd9a 100644 --- a/src/modal.c +++ b/src/modal.c @@ -177,13 +177,11 @@ find_register(Rule *r, char reg) } static char * -compile_rule(Rule *r, char *src) +compile_rule(Rule *r, int id, char *src) { - int i; char c, *s; + r->id = id, r->ptr = 0; r->a = dict_, src = parse_frag(src); - r->b = dict_, src = parse_frag(src); - r->ptr = 0; s = r->a; while((c = *s++)) { /* left */ if(c == '?') { @@ -193,6 +191,7 @@ compile_rule(Rule *r, char *src) *s = '0' + reg; } } + r->b = dict_, src = parse_frag(src); s = r->b; while((c = *s++)) { /* right */ if(c == '?') { @@ -213,15 +212,15 @@ rewrite(void) if(spacer(last)) { Rule *r = NULL; if(c == '<' && s[1] == '>') { /* rule */ - r = rules_++, r->id = rules_ - rules - 1; - s = compile_rule(r, s + 2); + r = rules_++; + s = compile_rule(r,rules_ - rules - 1, s + 2); while(*s == ' ') s++; return write_rule(r, s, 1); } if(c == '?' && s[1] == '(') { /* lambda */ cap = walk(s + 1); - r = &lambda, r->id = -1; - compile_rule(r, s + 2); + r = λ + compile_rule(r, -1, s + 2); s = cap; while(*s == ' ') s++; return apply_rule(&lambda, s);