Suppose I want to test `my-lexer` as a DrRacket syntax colorer. My idea is to 
create a miniature editor with `color-text%` and display it in DrRacket with 
`editor-snip%`. The code below will display a basic editor with black text. 

Q: How can I attach `my-lexer` to this editor so that the text is displayed in 
color? I don't think `start-colorer` is the answer, as this seems to be an 
internal method used by DrRacket. Meanwhile, the `color:text-mode-mixin` 
accepts a `get-token` argument, but I haven't figured out how to make this work 
with the `color:text%` class (or if it's even supposed to). 


#lang racket/base
(require racket/gui framework)

(define my-lexer (λ (port offset mode)
                    (define-values (line col pos) (port-next-location port))
                    (define c (read-char port))
                    (cond
                      [(eof-object? c)
                       (values c 'eof #f #f #f 0 mode)]
                      [else
                       (values (string c)
                               (if mode 'symbol 'string)
                               #f
                               (+ pos)
                               (+ pos 1)
                               0
                               (not mode))])))

(define editor (new color:text%))
;; how to attach my-lexer to editor here?
(send editor insert "foo bar world")
(make-object editor-snip% editor)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to