dev-srcloc
Matthew Butterick 8 years ago
parent bfd3690eca
commit 0dd59d8c13

@ -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]

@ -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)]

Loading…
Cancel
Save