Returned the input formatter

This commit is contained in:
Devine Lu Linvega 2024-05-17 09:45:30 -07:00
parent 97a686913c
commit fc903be471
4 changed files with 20 additions and 14 deletions

View File

@ -3,8 +3,8 @@
?(?: ?:) \#6c ?(?: ?:) \#6c
?(?: ?:) \#6c ?(?: ?:) \#6c
?(?: ?:) \#6f ?(?: ?:) \#6f
?(?: ?:) \#0a
?(?: ?:) \#ce ?(?: ?:) \#ce\#bb\#0a
?(?: ?:) \#bb ?(?: ?:) \#e9\#ad\#91\#e9\#ad\#85\#e9\#ad\#8d\#e9\#ad\#8e\#0a
?((?: ?0 ?1) ?:) + #34 #67 ?((?: ?0 ?1) ?:) + #34 #67

View File

@ -79,9 +79,8 @@ abc ?(?x) def = abc (lambda 2/2) test
?(?-) (Incomplete definitions) ?(?-) (Incomplete definitions)
<> (incomplete-basic) <> (incomplete-basic) ()
<> (incomplete-reg ?x) <> (incomplete-reg ?x) ()
<> <>
<> () () <> () ()
(incomplete-basic) = () (incomplete 1/4) test (incomplete-basic) = () (incomplete 1/4) test
@ -123,13 +122,15 @@ fruit_b -> banana
?(?-) (Arithmetic) ?(?-) (Arithmetic)
?((?: ?0 ?1 ?2) ?:) + 1 2 3 = 6 (Arithmetic 1/4) test ?((?: ?0 ?1 ?2) ?:) + 1 2 3 = 6 (Arithmetic 1/6) test
?((?0 ?: ?1) ?:) 16 - 8 = 8 (Arithmetic 2/4) test ?((?0 ?: ?1) ?:) 16 - 8 = 8 (Arithmetic 2/6) test
?((?0 ?1 ?:) ?:) 12 10 * = 120 (Arithmetic 3/4) test ?((?0 ?1 ?:) ?:) 12 10 * = 120 (Arithmetic 3/6) test
<> (?0 ?1 `?:) (?:) <> (?0 ?1 `?:) (?:)
(12 45 `+ -2 `+) = (55) (Arithmetic 4/4) test (12 45 `+ -2 `+) = (55) (Arithmetic 4/6) test
(#12 45 `+ -2 `+) = (#3d) (Arithmetic 5/6) test
(12 #45 `+ -2 `+) = (79) (Arithmetic 6/6) test
?(?-) (List reversal) ?(?-) (List reversal)

View File

@ -10,7 +10,7 @@ dest:
run: all bin/modal run: all bin/modal
@ bin/modal -q examples/hello.modal @ bin/modal -q examples/hello.modal
debug: all bin/modal-debug debug: all bin/modal-debug
@ bin/modal-debug -a examples/binary.modal @ bin/modal-debug examples/hello.modal
test: all bin/modal-debug bin/modal test: all bin/modal-debug bin/modal
@ bin/modal -v @ bin/modal -v
@ bin/modal-debug -q examples/fizzbuzz.modal @ bin/modal-debug -q examples/fizzbuzz.modal

View File

@ -103,12 +103,17 @@ file_import(char *path, char *ptr)
FILE *f; FILE *f;
int pr = 0; int pr = 0;
if((f = fopen(path, "r"))) { if((f = fopen(path, "r"))) {
unsigned char c; unsigned char c, last = 0;
while(fread(&c, 1, 1, f)) { while(fread(&c, 1, 1, f)) {
c = c <= 0x20 ? 0x20 : c; c = c <= 0x20 ? 0x20 : c;
if(c == '(') pr++; if(c == '(') pr++;
if(c == ')') pr--; if(c == ')') pr--;
*ptr++ = c; if(c == ' ' && last == '(') continue;
if(c == ')' && last == ' ') ptr--;
if(c == ' ' && last == ' ') ptr--;
if(c == '(' && last != '?' && !spacer(last)) *ptr++ = ' ';
if(last == ')' && !spacer(c)) *ptr++ = ' ';
*ptr++ = last = c;
} }
fclose(f); fclose(f);
if(pr) fprintf(stderr, "Modal program imbalanced.\n"); if(pr) fprintf(stderr, "Modal program imbalanced.\n");
@ -321,7 +326,7 @@ main(int argc, char **argv)
return !printf("usage: modal [-vqn] source.modal\n"); return !printf("usage: modal [-vqn] source.modal\n");
for(i = 1; i < argc && *argv[i] == '-'; i++) { for(i = 1; i < argc && *argv[i] == '-'; i++) {
switch(argv[i][1]) { switch(argv[i][1]) {
case 'v': /* version */ return !printf("Modal Interpreter, 13 May 2024.\n"); case 'v': /* version */ return !printf("Modal Interpreter, 17 May 2024.\n");
case 'q': /* quiet */ quiet = 1; break; case 'q': /* quiet */ quiet = 1; break;
case 'p': /* debug */ debug = 1; break; case 'p': /* debug */ debug = 1; break;
case 'a': /* access */ access = 1; break; case 'a': /* access */ access = 1; break;