diff --git a/beautiful-racket-demo/basic-demo/colorer.rkt b/beautiful-racket-demo/basic-demo/colorer.rkt index d490ced..8beb04a 100644 --- a/beautiful-racket-demo/basic-demo/colorer.rkt +++ b/beautiful-racket-demo/basic-demo/colorer.rkt @@ -2,17 +2,15 @@ (require brag/support syntax-color/racket-lexer racket/contract basic-demo/tokenizer sugar/coerce) -;(values lexeme 'parenthesis '|(| (pos lexeme-start) (pos lexeme-end)) - (define (color-basic ip) (define postok ((tokenize ip))) - (define tok-or-str (position-token-token postok)) - (define type (if (string? tok-or-str) - 'string - (token-struct-type tok-or-str))) - (define val (if (string? tok-or-str) - tok-or-str - (->string (or (token-struct-val tok-or-str) "")))) + (define tok (position-token-token postok)) + (define-values (type val) + (cond + [(eof-object? tok) (values 'eof "")] + [(string? tok) (values 'string tok)] + [else (values (token-struct-type tok) + (format "~a" (token-struct-val tok)))])) (values val (caseq type [(WHITE) 'white-space] diff --git a/beautiful-racket-demo/basic-demo/tokenizer.rkt b/beautiful-racket-demo/basic-demo/tokenizer.rkt index 98e9c8c..b63cc03 100644 --- a/beautiful-racket-demo/basic-demo/tokenizer.rkt +++ b/beautiful-racket-demo/basic-demo/tokenizer.rkt @@ -13,7 +13,7 @@ (define (next-token) (define get-token (lexer-src-pos - [(eof) (token 'EOF)] + [(eof) eof] [whitespace (token 'WHITE lexeme #:skip? #t)] [(from/to "/*" "*/") (token 'COMMENT lexeme #:skip? #t)] [(:: positive-number (:+ whitespace) (from/to (uc+lc "rem") "\n")) (token 'COMMENT lexeme #:skip? #t)]