Allow for empty right-hand side rules

This commit is contained in:
Devine Lu Linvega 2024-04-12 10:30:59 -07:00
parent 5249d7612d
commit ea9935babb
1 changed files with 12 additions and 10 deletions

View File

@ -19,7 +19,7 @@ walk(char *s)
{
char c;
int depth = 0;
if(s[0] == '(') {
if(*s == '(') {
while((c = *s++)) {
if(c == '(') depth++;
if(c == ')') --depth;
@ -36,7 +36,7 @@ plode(char *s)
int i, depth = 0;
char c, *ss;
/* implode */
if(s[0] == '(') {
if(*s == '(') {
ss = walk(s);
while(s < ss && (c = *s++))
if(!spacer(c)) *outp_++ = c;
@ -149,20 +149,22 @@ parse_frag(char *s)
{
char c, *ss;
while((c = *s) && c <= ' ') s++;
ss = walk(s);
if(*s == '(') s++, ss--;
while(s < ss) *dict_++ = *s++;
if(*s != ')' && *s != '<' && s[1] != '>') {
ss = walk(s);
if(*s == '(') s++, ss--;
while(s < ss) *dict_++ = *s++;
s++;
}
*dict_++ = 0;
s++;
return s;
}
static char *
create_rule(Rule *r, int id, char *s)
{
char c;
r->id = id, s += 2;
r->a = dict_, s = parse_frag(s), r->b = dict_, s = parse_frag(s);
r->a = dict_, s = parse_frag(s);
r->b = dict_, s = parse_frag(s);
return s;
}
@ -174,13 +176,13 @@ rewrite(void)
while((c = *s)) {
if(spacer(last)) {
Rule *r;
if(s[0] == '<' && s[1] == '>') {
if(*s == '<' && s[1] == '>') {
r = rules_++;
s = create_rule(r, rules_ - rules - 1, s);
while((c = *s) && c <= ' ') s++;
return commit_rule(r, s, 1);
}
if(s[0] == '?' && s[1] == '(') {
if(*s == '?' && s[1] == '(') {
r = &lambda, cap = walk(s + 1);
create_rule(&lambda, -1, s), s = cap;
while((c = *s) && c <= ' ') s++;