You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-demo/basic-demo-2/colorer.rkt

22 lines
825 B
Racket

#lang br
(require "lexer.rkt" brag/support)
(provide color-basic)
(define (color-basic port)
(define srcloc-tok (basic-lexer port))
(match srcloc-tok
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
[else ; reverse-engineer with `match-define`
(match-define (srcloc-token (token-struct type val _ _ _ _ _)
(srcloc _ _ _ pos span)) srcloc-tok)
(define (color cat [paren #f])
(values (or val "") cat paren pos (+ pos span)))
(match type
['STRING (color 'string)]
['REM (color 'comment)]
[else (match val
[(? number?) (color 'constant)]
[(? symbol?) (color 'symbol)]
["(" (color 'parenthesis '|(|)]
[")" (color 'parenthesis '|)|)]
[else (color 'no-color)])])]))