Last active
August 29, 2015 14:11
-
-
Save samth/2ab5c53ce0df34d1ac5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module+ test | |
(require rackunit check-sexp-equal) | |
(define (ts type tok) | |
(token-struct type tok #f #f #f #f #f)) | |
(define (pt val from to) | |
(position-token val (position from #f #f) (position to #f #f))) | |
(define (drain-lexer input) | |
(define ip (open-input-string input)) | |
(sequence->list (in-producer smalltalk/lex 'eof ip))) | |
(define (check-lex input . expecteds) | |
(define actuals (drain-lexer input)) | |
(check-equal (length expecteds) (length actuals) | |
(for ([expected expecteds] [actual actuals]) | |
(check-sexp-equal? actual expected))) | |
(define (tk t v m n) (pt (ts t v) m n)) | |
(check-lex "2 + 3" | |
(tk 'NUM "2" 1 2) | |
(tk 'BIN "*" 3 4) | |
(tk 'NUM "3" 5 6))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment