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

@ -2,17 +2,15 @@
(require brag/support syntax-color/racket-lexer racket/contract (require brag/support syntax-color/racket-lexer racket/contract
basic-demo/tokenizer sugar/coerce) basic-demo/tokenizer sugar/coerce)
;(values lexeme 'parenthesis '|(| (pos lexeme-start) (pos lexeme-end))
(define (color-basic ip) (define (color-basic ip)
(define postok ((tokenize ip))) (define postok ((tokenize ip)))
(define tok-or-str (position-token-token postok)) (define tok (position-token-token postok))
(define type (if (string? tok-or-str) (define-values (type val)
'string (cond
(token-struct-type tok-or-str))) [(eof-object? tok) (values 'eof "")]
(define val (if (string? tok-or-str) [(string? tok) (values 'string tok)]
tok-or-str [else (values (token-struct-type tok)
(->string (or (token-struct-val tok-or-str) "")))) (format "~a" (token-struct-val tok)))]))
(values val (values val
(caseq type (caseq type
[(WHITE) 'white-space] [(WHITE) 'white-space]

@ -13,7 +13,7 @@
(define (next-token) (define (next-token)
(define get-token (define get-token
(lexer-src-pos (lexer-src-pos
[(eof) (token 'EOF)] [(eof) eof]
[whitespace (token 'WHITE lexeme #:skip? #t)] [whitespace (token 'WHITE lexeme #:skip? #t)]
[(from/to "/*" "*/") (token 'COMMENT lexeme #:skip? #t)] [(from/to "/*" "*/") (token 'COMMENT lexeme #:skip? #t)]
[(:: positive-number (:+ whitespace) (from/to (uc+lc "rem") "\n")) (token 'COMMENT lexeme #:skip? #t)] [(:: positive-number (:+ whitespace) (from/to (uc+lc "rem") "\n")) (token 'COMMENT lexeme #:skip? #t)]

Loading…
Cancel
Save