Progress in merging parsers
This commit is contained in:
parent
23ec4856e0
commit
bcbfe02783
15
src/modal.c
15
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);
|
||||
|
|
Loading…
Reference in New Issue