commit 4c7112242abf30988945134ef192c73af15f5d3b (patch)
parent 250d47442f24442cd28b704e8b237811a4534e9a
Author: Alex Karle <alex@alexkarle.com>
Date: Wed, 5 Oct 2022 00:00:49 -0400
scanner: Use define-record instead of alist
This allows a better printout and more *struct*ured types :)
Diffstat:
3 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/fisl.scm b/fisl.scm
@@ -24,8 +24,8 @@
(define (run-file fname)
(call-with-input-file fname (lambda (p)
- (run (read-string #f p) fname)
- (exit (if had-err 1 0)))))
+ (run (read-string #f p) fname)
+ (exit (if had-err 1 0)))))
(define (main args)
(let ((argc (length args)))
diff --git a/scanner.scm b/scanner.scm
@@ -7,11 +7,12 @@
(chicken base)
(chicken format))
- (define (make-token type lexeme literal line)
- `((type ,type)
- (lexeme ,lexeme)
- (literal ,literal)
- (line ,line)))
+ ; Auto-generates the scaffolding getters and setters
+ ; make-token, token-type, set-token-type!, etc
+ (define-record token type lexeme literal line)
+ (set-record-printer! token (lambda (t out)
+ (fprintf out "#,(token type:~S lex:~S lit:~S ln:~S)"
+ (token-type t) (token-lexeme t) (token-literal t) (token-line t))))
(define (digit? c)
(and c (char<=? #\0 c) (char>=? #\9 c)))
@@ -42,8 +43,6 @@
("while" WHILE)))))
(if kpair (cadr kpair) #f)))
-
-
(define (alnum? c)
(and c (or (alpha? c) (digit? c))))
diff --git a/util.scm b/util.scm
@@ -1,4 +1,4 @@
-(module util (die get err! had-err clear-err!)
+(module util (die err! had-err clear-err!)
(import scheme
(chicken base)
(chicken io)
@@ -16,12 +16,4 @@
(define (die str)
(err! str)
(exit 1))
-
- (define (get assoc-arr key)
- ;; fetch from assoc array and error if key not found
- (let ((tup (assoc key assoc-arr)))
- (if tup
- (cadr tup)
- (error (format "bad key ~A" key)))))
-
) ; end of module