fisl

fisl is scheme lox
git clone git://git.alexkarle.com.com/fisl
Log | Files | Refs | README | LICENSE

commit 250d47442f24442cd28b704e8b237811a4534e9a (patch)
parent be6df7f081b8c1d9c10d6149d44c9f512680c229
Author: Alex Karle <alex@alexkarle.com>
Date:   Tue,  4 Oct 2022 23:52:54 -0400

scanner: Clean up with optional function params

Reading the base module wiki [1] and found this gem.

[1]: http://wiki.call-cc.org/man/5/Module%20(chicken%20base)#binding-forms-for-optional-arguments

Diffstat:
Mscanner.scm | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/scanner.scm b/scanner.scm @@ -74,13 +74,13 @@ ; helper to tokenize current span (tok-range type s i)) - (define (skip) + (define (skip . line2) ; Helper to skip this character range - (get-tokens (add1 i) (add1 i) line in)) + (get-tokens (add1 i) (add1 i) (optional line2 line) in)) - (define (advance l2) + (define (advance . line2) ; Helper to iterate; keeps start but increments range - (get-tokens s (add1 i) l2 in)) + (get-tokens s (add1 i) (optional line2 line) in)) (let ((c (peek i)) (n (peek (add1 i)))) (if (and (not in) (not c)) @@ -88,25 +88,25 @@ (cond ((eq? in 'comment) (if (or (not c) (eq? #\newline c)) (get-tokens (add1 i) (add1 i) (add1 line) #f) - (advance line))) + (advance))) ((eq? in 'string) (cond ((not c) (err! (format "~A:~A:unterminated string" fname line))) ((eq? #\" c) (tok 'STRING)) ((eq? #\newline c) (advance (add1 line))) - (else (advance line)))) + (else (advance)))) ((eq? in 'number) (cond - ((digit? c) (advance line)) + ((digit? c) (advance)) ((eq? #\. c) (get-tokens s (add1 i) line 'decimal)) (else (tok-range 'NUMBER s (sub1 i))))) ((eq? in 'decimal) (cond - ((digit? c) (advance line)) + ((digit? c) (advance)) (else (tok-range 'NUMBER s (sub1 i))))) ((eq? in 'alpha) (cond - ((alnum? c) (advance line)) + ((alnum? c) (advance)) (else (tok-range 'IDENTIFIER s (sub1 i))))) (else (cond ((eq? #\( c) (tok 'LEFT_PAREN)) @@ -129,7 +129,7 @@ ((alpha? c) (get-tokens s (add1 i) line 'alpha)) ((eq? #\space c) (skip)) ((eq? #\tab c) (skip)) - ((eq? #\newline c) (get-tokens (add1 i) (add1 i) (add1 line) in)) + ((eq? #\newline c) (skip (add1 line))) (else (err! (format "~A:~A:unexpected character: ~A" fname line c)) (skip)))))))) (get-tokens 0 0 1 #f))