diff --git a/examples/tests.modal b/examples/tests.modal index 01a175e..cc8a36b 100644 --- a/examples/tests.modal +++ b/examples/tests.modal @@ -6,12 +6,14 @@ <> (ghost) () -?(?-) (Whitespace) +?(?-) (Formatter) -(a b c ) = (a b c) (whitespace 1) test -( a b c) = (a b c) (whitespace 2) test -( a b c ) = (a b c) (whitespace 3) test -(a b c ( a b c ) ) = (a b c (a b c)) (whitespace 4) test +?((?x ?y) one) aaa(bbb) = one (formatter 1) test +?((?x ?y) one) (bbb)aaa = one (formatter 2) test +(a b c ) = (a b c) (formatter 3) test +( a b c) = (a b c) (formatter 4) test +( a b c ) = (a b c) (formatter 5) test +(a b c ( a b c ) ) = (a b c (a b c)) (formatter 6) test ?(?-) (Empty replacements) diff --git a/src/modal.c b/src/modal.c index 32562fc..0c1a83f 100644 --- a/src/modal.c +++ b/src/modal.c @@ -124,9 +124,9 @@ apply_rule(Rule *r, char *s) if(*reg++ != *pp++) return 0; } else /* reg set */ regs[id] = s; - c = *a, s = pcap; - } - else if(c != *s++) return 0; + s = pcap; + } else if(c != *s++) + return 0; } c = *s; if(!spacer(c)) return 0; @@ -232,7 +232,7 @@ main(int argc, char **argv) { FILE *f; int i, pl = 0, pr = 0; - char c, *w = bank_a; + char c, last = 0, *w = bank_a; if(argc < 2) return !printf("usage: modal [-vqn] source.modal\n"); for(i = 1; i < argc && *argv[i] == '-'; i++) { @@ -246,14 +246,14 @@ main(int argc, char **argv) return !fprintf(stdout, "Modal file invalid: %s.\n", argv[i]); while(fread(&c, 1, 1, f)) { c = c <= 0x20 ? 0x20 : c; - if(w > bank_a) { - if(c == ' ' && *(w - 1) == '(') continue; - if(c == ')' && *(w - 1) == ' ') w--; - if(c == ' ' && *(w - 1) == ' ') w--; - } + if(c == ' ' && last == '(') continue; + if(c == ')' && last == ' ') w--; + if(c == ' ' && last == ' ') w--; if(c == '(') pl++; if(c == ')') pr++; - *w++ = c; + if(c == '(' && last != '?' && !spacer(last)) *w++ = ' '; + if(last == ')' && !spacer(c)) *w++ = ' '; + *w++ = last = c; } while(*(--w) <= ' ') *w = 0; fclose(f);