Housekeeping
This commit is contained in:
parent
399ac8dd17
commit
5ab8e10a6b
37
src/modal.c
37
src/modal.c
|
@ -153,54 +153,45 @@ find_register(Rule *r, char reg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < (int)r->ptr; i++)
|
for(i = 0; i < (int)r->ptr; i++)
|
||||||
if(r->key[i] == reg)
|
if(r->key[i] == reg) return i;
|
||||||
return i;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
compile_rule(Rule *r, int id, char *src)
|
compile_rule(Rule *r, int id, char *src)
|
||||||
{
|
{
|
||||||
int wrapped, reg;
|
|
||||||
char c, *cap;
|
char c, *cap;
|
||||||
|
int wrapped, reg;
|
||||||
r->id = id, r->ptr = 0, r->a = &empty, r->b = ∅
|
r->id = id, r->ptr = 0, r->a = &empty, r->b = ∅
|
||||||
/* phase: left */
|
/* phase: left */
|
||||||
while((c = *src) && c == ' ') src++;
|
while((c = *src) && c == ' ') src++;
|
||||||
if(c == ')' || (c == '<' && src[1] == '>')) return src;
|
if(c == ')' || (c == '<' && src[1] == '>')) return src;
|
||||||
r->a = dict_;
|
r->a = dict_, cap = walk(src), wrapped = c == '(';
|
||||||
cap = walk(src);
|
|
||||||
wrapped = c == '(';
|
|
||||||
if(wrapped) src++, cap--;
|
if(wrapped) src++, cap--;
|
||||||
while(src < cap) {
|
while(src < cap) {
|
||||||
if(*src == '?') {
|
c = *src, *dict_++ = *src++;
|
||||||
*dict_++ = *src++;
|
if(c == '?') {
|
||||||
reg = find_register(r, *src);
|
reg = find_register(r, *src);
|
||||||
if(reg < 0 && *src != '(')
|
if(reg == -1 && *src != '(')
|
||||||
r->key[r->ptr] = *src, reg = r->ptr++;
|
r->key[r->ptr] = *src, reg = r->ptr++;
|
||||||
*dict_++ = '0' + reg;
|
*dict_++ = '0' + reg;
|
||||||
} else
|
|
||||||
*dict_++ = *src++;
|
|
||||||
}
|
}
|
||||||
src += wrapped;
|
}
|
||||||
*dict_++ = 0;
|
src += wrapped, *dict_++ = 0;
|
||||||
/* phase: right */
|
/* phase: right */
|
||||||
while((c = *src) && c == ' ') src++;
|
while((c = *src) && c == ' ') src++;
|
||||||
if(c == ')' || (c == '<' && src[1] == '>')) return src;
|
if(c == ')' || (c == '<' && src[1] == '>')) return src;
|
||||||
r->b = dict_;
|
r->b = dict_, cap = walk(src), wrapped = c == '(';
|
||||||
cap = walk(src);
|
|
||||||
wrapped = c == '(';
|
|
||||||
if(wrapped) src++, cap--;
|
if(wrapped) src++, cap--;
|
||||||
while(src < cap) {
|
while(src < cap) {
|
||||||
if(*src == '?') {
|
c = *src, *dict_++ = *src++;
|
||||||
*dict_++ = *src++;
|
if(c == '?') {
|
||||||
reg = find_register(r, *src);
|
reg = find_register(r, *src);
|
||||||
*dict_++ = reg >= 0 ? ('0' + reg) : *src;
|
*dict_++ = reg != -1 ? '0' + reg : *src;
|
||||||
src++;
|
src++;
|
||||||
} else
|
|
||||||
*dict_++ = *src++;
|
|
||||||
}
|
}
|
||||||
src += wrapped;
|
}
|
||||||
*dict_++ = 0;
|
src += wrapped, *dict_++ = 0;
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue