Skip to content

Instantly share code, notes, and snippets.

@samth
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samth/2ab5c53ce0df34d1ac5e to your computer and use it in GitHub Desktop.
Save samth/2ab5c53ce0df34d1ac5e to your computer and use it in GitHub Desktop.
(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