Progress on rules compilation

This commit is contained in:
Devine Lu Linvega 2024-04-24 14:22:23 -07:00
parent 53ef87a4b9
commit 97d406c3a8
1 changed files with 13 additions and 14 deletions

View File

@ -161,21 +161,21 @@ find_register(Rule *r, char reg)
static char * static char *
compile_rule(Rule *r, int id, char *src) compile_rule(Rule *r, int id, char *src)
{ {
int wrapped;
char c, *cap, *s, *s2; char c, *cap, *s, *s2;
r->id = id, r->ptr = 0; r->id = id, r->ptr = 0;
/* left */ /* left ==================================== */
r->a = dict_; r->a = dict_;
s2 = src; s2 = src;
while((c = *s2) && c == ' ') s2++; while((c = *s2) && c == ' ') s2++;
if(c != ')' && !(c == '<' && s2[1] == '>')) { if(c != ')' && !(c == '<' && s2[1] == '>')) {
cap = walk(s2); cap = walk(s2);
if(c == '(') { wrapped = c == '(';
s2++; if(wrapped) s2++, cap--;
while(s2 < cap - 1) *dict_++ = *s2++; while(s2 < cap) *dict_++ = *s2++;
s2++; s2 += wrapped;
} else
while(s2 < cap) *dict_++ = *s2++;
} }
*dict_++ = 0; *dict_++ = 0;
src = s2; src = s2;
@ -190,18 +190,17 @@ compile_rule(Rule *r, int id, char *src)
} }
} }
/* right */ /* right ==================================== */
r->b = dict_; r->b = dict_;
s2 = src; s2 = src;
while((c = *s2) && c == ' ') s2++; while((c = *s2) && c == ' ') s2++;
if(c != ')' && !(c == '<' && s2[1] == '>')) { if(c != ')' && !(c == '<' && s2[1] == '>')) {
cap = walk(s2); cap = walk(s2);
if(c == '(') { wrapped = c == '(';
s2++; if(wrapped) s2++, cap--;
while(s2 < cap - 1) *dict_++ = *s2++; while(s2 < cap) *dict_++ = *s2++;
s2++; s2 += wrapped;
} else
while(s2 < cap) *dict_++ = *s2++;
} }
*dict_++ = 0; *dict_++ = 0;
src = s2; src = s2;