Added tests for formatter
This commit is contained in:
parent
3167698795
commit
a7abb9475a
|
@ -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)
|
||||
|
||||
|
|
20
src/modal.c
20
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);
|
||||
|
|
Loading…
Reference in New Issue