Inline rule parsing
This commit is contained in:
parent
7147e8e5ad
commit
3c99fb47f6
|
@ -1,4 +1,3 @@
|
||||||
<> (eq ?x ?x) (#t)
|
<> ((?x -> ?y)) (<> ?x ?y)
|
||||||
<> (eq ?x ?y) (#f)
|
|
||||||
|
|
||||||
(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 == ')')
|
#define spacer(c) (c == ' ' || c == '(' || c == ')')
|
||||||
|
|
||||||
|
static char *parse_rulefrag(char *line);
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
walk(char *s)
|
walk(char *s)
|
||||||
{
|
{
|
||||||
|
@ -92,12 +94,26 @@ save(int rule)
|
||||||
printf("%02d %s\n", rule, prog);
|
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
|
static int
|
||||||
rewrite(void)
|
rewrite(void)
|
||||||
{
|
{
|
||||||
char c, *p = prog;
|
char c, *p = prog;
|
||||||
while((c = *p)) {
|
while((c = *p)) {
|
||||||
int i;
|
int i;
|
||||||
|
if(p[0] == '<' && p[1] == '>')
|
||||||
|
p = addrule(p) + 1, c = *p;
|
||||||
for(i = 0; i < rules_len; i++) {
|
for(i = 0; i < rules_len; i++) {
|
||||||
Rule *r = &rules[i];
|
Rule *r = &rules[i];
|
||||||
char *res = match(p, r);
|
char *res = match(p, r);
|
||||||
|
|
Loading…
Reference in New Issue