Inline rule parsing
This commit is contained in:
parent
7147e8e5ad
commit
3c99fb47f6
|
@ -1,4 +1,3 @@
|
|||
<> (eq ?x ?x) (#t)
|
||||
<> (eq ?x ?y) (#f)
|
||||
<> ((?x -> ?y)) (<> ?x ?y)
|
||||
|
||||
(eq fox fox) (eq fox owl)
|
||||
(foo -> bar) foo
|
16
src/modal.c
16
src/modal.c
|
@ -13,6 +13,8 @@ static char *regs[0x100];
|
|||
|
||||
#define spacer(c) (c == ' ' || c == '(' || c == ')')
|
||||
|
||||
static char *parse_rulefrag(char *line);
|
||||
|
||||
static char *
|
||||
walk(char *s)
|
||||
{
|
||||
|
@ -92,12 +94,26 @@ save(int rule)
|
|||
printf("%02d %s\n", rule, prog);
|
||||
}
|
||||
|
||||
static char *
|
||||
addrule(char *s)
|
||||
{
|
||||
Rule *r = &rules[rules_len++];
|
||||
s += 3;
|
||||
r->a = parse_rulefrag(s);
|
||||
s = walk(s) + 1;
|
||||
r->b = parse_rulefrag(s);
|
||||
s = walk(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
static int
|
||||
rewrite(void)
|
||||
{
|
||||
char c, *p = prog;
|
||||
while((c = *p)) {
|
||||
int i;
|
||||
if(p[0] == '<' && p[1] == '>')
|
||||
p = addrule(p) + 1, c = *p;
|
||||
for(i = 0; i < rules_len; i++) {
|
||||
Rule *r = &rules[i];
|
||||
char *res = match(p, r);
|
||||
|
|
Loading…
Reference in New Issue