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 *
|
static char *
|
||||||
compile_rule(Rule *r, char *src)
|
compile_rule(Rule *r, int id, char *src)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
char c, *s;
|
char c, *s;
|
||||||
|
r->id = id, r->ptr = 0;
|
||||||
r->a = dict_, src = parse_frag(src);
|
r->a = dict_, src = parse_frag(src);
|
||||||
r->b = dict_, src = parse_frag(src);
|
|
||||||
r->ptr = 0;
|
|
||||||
s = r->a;
|
s = r->a;
|
||||||
while((c = *s++)) { /* left */
|
while((c = *s++)) { /* left */
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
|
@ -193,6 +191,7 @@ compile_rule(Rule *r, char *src)
|
||||||
*s = '0' + reg;
|
*s = '0' + reg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
r->b = dict_, src = parse_frag(src);
|
||||||
s = r->b;
|
s = r->b;
|
||||||
while((c = *s++)) { /* right */
|
while((c = *s++)) { /* right */
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
|
@ -213,15 +212,15 @@ rewrite(void)
|
||||||
if(spacer(last)) {
|
if(spacer(last)) {
|
||||||
Rule *r = NULL;
|
Rule *r = NULL;
|
||||||
if(c == '<' && s[1] == '>') { /* rule */
|
if(c == '<' && s[1] == '>') { /* rule */
|
||||||
r = rules_++, r->id = rules_ - rules - 1;
|
r = rules_++;
|
||||||
s = compile_rule(r, s + 2);
|
s = compile_rule(r,rules_ - rules - 1, s + 2);
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
return write_rule(r, s, 1);
|
return write_rule(r, s, 1);
|
||||||
}
|
}
|
||||||
if(c == '?' && s[1] == '(') { /* lambda */
|
if(c == '?' && s[1] == '(') { /* lambda */
|
||||||
cap = walk(s + 1);
|
cap = walk(s + 1);
|
||||||
r = &lambda, r->id = -1;
|
r = λ
|
||||||
compile_rule(r, s + 2);
|
compile_rule(r, -1, s + 2);
|
||||||
s = cap;
|
s = cap;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
return apply_rule(&lambda, s);
|
return apply_rule(&lambda, s);
|
||||||
|
|
Loading…
Reference in New Issue