Inlined parse_frag

This commit is contained in:
Devine Lu Linvega 2024-04-24 14:03:14 -07:00
parent 9d4d20e542
commit 53ef87a4b9
1 changed files with 35 additions and 21 deletions

View File

@ -148,24 +148,6 @@ apply_rule(Rule *r, char *s)
return 0;
}
static char *
parse_frag(char *s)
{
char c, *cap;
while((c = *s) && c == ' ') s++;
if(c != ')' && !(c == '<' && s[1] == '>')) {
cap = walk(s);
if(c == '(') {
s++;
while(s < cap - 1) *dict_++ = *s++;
s++;
} else
while(s < cap) *dict_++ = *s++;
}
*dict_++ = 0;
return s;
}
static int
find_register(Rule *r, char reg)
{
@ -179,9 +161,25 @@ find_register(Rule *r, char reg)
static char *
compile_rule(Rule *r, int id, char *src)
{
char c, *s;
char c, *cap, *s, *s2;
r->id = id, r->ptr = 0;
r->a = dict_, src = parse_frag(src);
/* left */
r->a = dict_;
s2 = src;
while((c = *s2) && c == ' ') s2++;
if(c != ')' && !(c == '<' && s2[1] == '>')) {
cap = walk(s2);
if(c == '(') {
s2++;
while(s2 < cap - 1) *dict_++ = *s2++;
s2++;
} else
while(s2 < cap) *dict_++ = *s2++;
}
*dict_++ = 0;
src = s2;
s = r->a;
while((c = *s++)) { /* left */
if(c == '?') {
@ -191,7 +189,23 @@ compile_rule(Rule *r, int id, char *src)
*s = '0' + reg;
}
}
r->b = dict_, src = parse_frag(src);
/* right */
r->b = dict_;
s2 = src;
while((c = *s2) && c == ' ') s2++;
if(c != ')' && !(c == '<' && s2[1] == '>')) {
cap = walk(s2);
if(c == '(') {
s2++;
while(s2 < cap - 1) *dict_++ = *s2++;
s2++;
} else
while(s2 < cap) *dict_++ = *s2++;
}
*dict_++ = 0;
src = s2;
s = r->b;
while((c = *s++)) { /* right */
if(c == '?') {