Made lexer unit tests compilable

This commit is contained in:
2025-10-25 20:42:36 +02:00
parent f53dda3c0f
commit 9d5d55c8f4
3 changed files with 44 additions and 8 deletions

View File

@@ -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.)

View File

@@ -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))

1
sigma
View File

@@ -1 +0,0 @@
Hello, world!