diff --git a/examples/test.modal b/examples/test.modal index 6f157a8..310551e 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -1,4 +1,3 @@ -<> (eq ?x ?x) (#t) -<> (eq ?x ?y) (#f) +<> ((?x -> ?y)) (<> ?x ?y) -(eq fox fox) (eq fox owl) \ No newline at end of file +(foo -> bar) foo \ No newline at end of file diff --git a/src/modal.c b/src/modal.c index ae9fd75..422519f 100644 --- a/src/modal.c +++ b/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);