From fc903be471d0687ce0f8d82e3bd62fedf32241cc Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 17 May 2024 09:45:30 -0700 Subject: [PATCH] Returned the input formatter --- examples/binary.modal | 6 +++--- examples/tests.modal | 15 ++++++++------- makefile | 2 +- src/modal.c | 11 ++++++++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/binary.modal b/examples/binary.modal index d43dce0..c0b924f 100644 --- a/examples/binary.modal +++ b/examples/binary.modal @@ -3,8 +3,8 @@ ?(?: ?:) \#6c ?(?: ?:) \#6c ?(?: ?:) \#6f +?(?: ?:) \#0a -?(?: ?:) \#ce -?(?: ?:) \#bb - +?(?: ?:) \#ce\#bb\#0a +?(?: ?:) \#e9\#ad\#91\#e9\#ad\#85\#e9\#ad\#8d\#e9\#ad\#8e\#0a ?((?: ?0 ?1) ?:) + #34 #67 diff --git a/examples/tests.modal b/examples/tests.modal index 4438ef0..5b80968 100644 --- a/examples/tests.modal +++ b/examples/tests.modal @@ -79,9 +79,8 @@ abc ?(?x) def = abc (lambda 2/2) test ?(?-) (Incomplete definitions) -<> (incomplete-basic) -<> (incomplete-reg ?x) -<> <> +<> (incomplete-basic) () +<> (incomplete-reg ?x) () <> () () (incomplete-basic) = () (incomplete 1/4) test @@ -123,13 +122,15 @@ fruit_b -> banana ?(?-) (Arithmetic) -?((?: ?0 ?1 ?2) ?:) + 1 2 3 = 6 (Arithmetic 1/4) test -?((?0 ?: ?1) ?:) 16 - 8 = 8 (Arithmetic 2/4) test -?((?0 ?1 ?:) ?:) 12 10 * = 120 (Arithmetic 3/4) test +?((?: ?0 ?1 ?2) ?:) + 1 2 3 = 6 (Arithmetic 1/6) test +?((?0 ?: ?1) ?:) 16 - 8 = 8 (Arithmetic 2/6) test +?((?0 ?1 ?:) ?:) 12 10 * = 120 (Arithmetic 3/6) test <> (?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) diff --git a/makefile b/makefile index a7e9458..b785838 100644 --- a/makefile +++ b/makefile @@ -10,7 +10,7 @@ dest: run: all bin/modal @ bin/modal -q examples/hello.modal 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 @ bin/modal -v @ bin/modal-debug -q examples/fizzbuzz.modal diff --git a/src/modal.c b/src/modal.c index 1d41808..451279b 100644 --- a/src/modal.c +++ b/src/modal.c @@ -103,12 +103,17 @@ file_import(char *path, char *ptr) FILE *f; int pr = 0; if((f = fopen(path, "r"))) { - unsigned char c; + unsigned char c, last = 0; while(fread(&c, 1, 1, f)) { c = c <= 0x20 ? 0x20 : c; 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); 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"); for(i = 1; i < argc && *argv[i] == '-'; i++) { 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 'p': /* debug */ debug = 1; break; case 'a': /* access */ access = 1; break;