diff --git a/examples/hello.modal b/examples/hello.modal index f58037f..a417206 100644 --- a/examples/hello.modal +++ b/examples/hello.modal @@ -1,4 +1,6 @@ -<> (?: print) () +<> (NAME) (Modal) +<> (?: print $) (?:) +<> ($ ?x) (?x $) -(Welcome to Modal! -Have fun.\n) print +$ (Welcome to NAME +Have fun!) print \ No newline at end of file diff --git a/examples/test.modal b/examples/test.modal index 20476c8..ce61fe4 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -4,7 +4,6 @@ <> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l)) <> (reverse/l (?h) ?l) (str (?h ?l)) <> (implode str ?*) (?*) -<> ((read)) (?:) <> (empty-register) (?x) <> (explode ?*) (str (?*)) <> (eq ?x ?x) (#t) @@ -14,4 +13,4 @@ <> (?x pop) () <> (print ?:) () -(implode reverse (explode hello)) (read) (explode hello) empty-register (eq abc abc) (eq abc def) (1 2 3) (4 5 6) swap pop dup (hey 1234 pop) (print Done.) \ No newline at end of file +(implode reverse (explode hello)) (explode hello) empty-register (eq abc abc) (eq abc def) (1 2 3) (4 5 6) swap pop dup (hey 1234 pop) (print Done.) \ No newline at end of file diff --git a/src/modal.c b/src/modal.c index 500863e..45ce9a8 100644 --- a/src/modal.c +++ b/src/modal.c @@ -62,14 +62,6 @@ set_reg(int r, char *b) char *a = regs[r], *aa = walk(a), *bb = walk(b); while(a < aa && b < bb) if(*a++ != *b++) return 0; - } else if(r == ':') { - char *bb = walk(b); - if(*b == '(') b++, --bb; - while(b < bb) { - char c = *(b++); - if(c == '\\' && *(b++) == 'n') c = 0xa; - putc(c, stdout); - } } else regs[r] = b; return 1; @@ -81,7 +73,15 @@ put_reg(char r) char *s = regs[(int)r]; if(r == '*') s = plode(s); - else if(s) { + else if(r == ':') { + char *bb = walk(s); + if(*s == '(') s++, --bb; + while(s < bb) { + char c = *(s++); + if(c == '\\' && *(s++) == 'n') c = 0xa; + putc(c, stdout); + } + } else if(s) { char *ss = walk(s); while((s < ss)) *outp_++ = *s++; } else @@ -95,8 +95,7 @@ match_rule(char *p, Rule *r) int i; char c, *a = r->a, *b = p; for(i = 0x21; i < 0x7f; i++) - if((char)i != ':') - regs[i] = 0; + regs[i] = 0; while((c = *a)) { if(c == '?') { if(!set_reg(*(++a), b)) return NULL; @@ -211,7 +210,6 @@ main(int argc, char **argv) } while(*(--w) <= ' ') *w = 0; fclose(f); - regs[':'] = argv[2]; while(rewrite()) ; print_rules();