Use NULL for empty rules
This commit is contained in:
parent
79b9831f27
commit
e80db68aa6
|
@ -79,8 +79,6 @@ abc ?(?x) def = abc (lambda 2/2) test
|
||||||
|
|
||||||
?(?-) (Incomplete definitions)
|
?(?-) (Incomplete definitions)
|
||||||
|
|
||||||
<> <>
|
|
||||||
<> () ()
|
|
||||||
<> (incomplete-basic)
|
<> (incomplete-basic)
|
||||||
<> (incomplete-reg ?x)
|
<> (incomplete-reg ?x)
|
||||||
<> (waste-rule) *
|
<> (waste-rule) *
|
||||||
|
|
13
src/modal.c
13
src/modal.c
|
@ -7,7 +7,7 @@ typedef struct {
|
||||||
|
|
||||||
static int flip, quiet, debug, access, cycles = 0x200000;
|
static int flip, quiet, debug, access, cycles = 0x200000;
|
||||||
static Rule rules[0x1000], *rules_ = rules;
|
static Rule rules[0x1000], *rules_ = rules;
|
||||||
static char dict[0x8000], *dict_ = dict, empty;
|
static char dict[0x8000], *dict_ = dict;
|
||||||
static char bank_a[0x4000], *src_ = bank_a;
|
static char bank_a[0x4000], *src_ = bank_a;
|
||||||
static char bank_b[0x4000], *dst_ = bank_b;
|
static char bank_b[0x4000], *dst_ = bank_b;
|
||||||
static char *regs[0x100], stack[0x10], *stack_ = stack;
|
static char *regs[0x100], stack[0x10], *stack_ = stack;
|
||||||
|
@ -206,7 +206,8 @@ apply_rule(Rule *r, char *s)
|
||||||
c = *s;
|
c = *s;
|
||||||
if(!spacer(c)) return 0;
|
if(!spacer(c)) return 0;
|
||||||
/* phase: write rule */
|
/* phase: write rule */
|
||||||
while((c = *b++)) {
|
if(b != NULL) {
|
||||||
|
while((c = *b++))
|
||||||
if(c == '?' && (rid = *b) && (reg = regs[rid]))
|
if(c == '?' && (rid = *b) && (reg = regs[rid]))
|
||||||
write_reg(rid, reg), b++;
|
write_reg(rid, reg), b++;
|
||||||
else
|
else
|
||||||
|
@ -226,7 +227,7 @@ parse_frag(char **side, char *s)
|
||||||
char c, *cap;
|
char c, *cap;
|
||||||
while((c = *s) && c == ' ') s++;
|
while((c = *s) && c == ' ') s++;
|
||||||
if(c == ')' || (c == '<' || c == '>'))
|
if(c == ')' || (c == '<' || c == '>'))
|
||||||
*side = ∅
|
*side = NULL;
|
||||||
else {
|
else {
|
||||||
cap = walk(s), *side = dict_;
|
cap = walk(s), *side = dict_;
|
||||||
if(c == '(')
|
if(c == '(')
|
||||||
|
@ -277,7 +278,7 @@ rewrite(void)
|
||||||
if(c == '<' && s[1] == '>') {
|
if(c == '<' && s[1] == '>') {
|
||||||
r = rules_, r->id = rules_ - rules;
|
r = rules_, r->id = rules_ - rules;
|
||||||
s = parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
s = parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
||||||
if(*r->a) {
|
if(r->a != NULL) {
|
||||||
if(!quiet) fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
if(!quiet) fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||||
rules_++;
|
rules_++;
|
||||||
}
|
}
|
||||||
|
@ -292,13 +293,13 @@ rewrite(void)
|
||||||
parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
||||||
s = cap;
|
s = cap;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
if(r->a && !apply_rule(r, s)) write_tail(s);
|
if(r->a == NULL || !apply_rule(r, s)) write_tail(s);
|
||||||
dict_ = d;
|
dict_ = d;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* phase: match */
|
/* phase: match */
|
||||||
for(r = rules; r < rules_; r++)
|
for(r = rules; r < rules_; r++)
|
||||||
if(r->a && apply_rule(r, s)) return 1;
|
if(r->a != NULL && apply_rule(r, s)) return 1;
|
||||||
}
|
}
|
||||||
*dst_++ = last = c, s++;
|
*dst_++ = last = c, s++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue