From 9d5d55c8f47d1572b00180bece3d7aeec28693e7 Mon Sep 17 00:00:00 2001 From: Artsiom Dzenisiuk Date: Sat, 25 Oct 2025 20:42:36 +0200 Subject: [PATCH] Made lexer unit tests compilable --- README.md | 7 +++++-- fudge-chez.ss | 44 +++++++++++++++++++++++++++++++++++++++----- sigma | 1 - 3 files changed, 44 insertions(+), 8 deletions(-) delete mode 100644 sigma diff --git a/README.md b/README.md index a7952fe..5981304 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # Fudge-chez -This is the Fudge programming language implemented in Chez scheme. For the origin project, go to Wannie's [repository](https://shit-co.de/wanniepannie/fudge2.1). +This is the Fudge programming language implemented in Chez scheme. +For the original project, go to Wannie's +[repository](https://shit-co.de/wanniepannie/fudge2.1). # Installation -To run fudge-chez, install [Chez](https://scheme.com) and run the program with ```chez --program fudge-chez.ss``` +To run fudge-chez, install [Chez](https://scheme.com) and run the +program with ```chez --program fudge-chez.ss``` ## Why Chez scheme? Because Scheme is elegant. (In theory.) diff --git a/fudge-chez.ss b/fudge-chez.ss index 087ce23..7c53faf 100644 --- a/fudge-chez.ss +++ b/fudge-chez.ss @@ -4,6 +4,7 @@ (lambda (file) (let ([c (lookahead-char file)]) (cond + [(eof-object? c) ""] [(char-alphabetic? c) (get-char file) (string-append (string c) (get-word file))] @@ -55,13 +56,46 @@ (let ([file (open-input-file filename)]) (get-tokens file)))) +(define test-lexer-fail + (lambda (input want got) + (display "text-lexer-fail: input=") + (write input) + (display "; want: ") + (write want) + (display "; got: ") + (write got) + (display ".") + (newline))) + +(define test-lexer-success + (lambda (input got) + (display "text-lexer-success: input=") + (write input) + (display "; got: ") + (write got) + (display ".") + (newline))) + (define test-lexer (lambda (input want) (let ([port (open-string-input-port input)]) - (let ([got (get-tokens port)]) - (unless (eq? got want) - (text-lexer-fail input want got)))))) + (call/cc + (lambda (i-got-exception) + (with-exception-handler + (lambda (x) + (display "test-lexer-fail: input ") + (write input) + (display " throws ") + (write x) + (display ".") + (newline) + (i-got-exception x)) + (lambda () + (let ([got (get-tokens port)]) + (if (equal? got want) + (test-lexer-success input got) + (test-lexer-fail input want got)))))))))) (test-lexer "hello world" '("hello" "world")) -(test-lexer "+ * / -", '(+ * / -)) -(test-lexer "identifier = 14", '("identifier" = 14)) +(test-lexer "+ * / -" '(+ * / -)) +(test-lexer "identifier = 14" '("identifier" = 14)) diff --git a/sigma b/sigma deleted file mode 100644 index 5dd01c1..0000000 --- a/sigma +++ /dev/null @@ -1 +0,0 @@ -Hello, world! \ No newline at end of file