For testing your lexer, I think you probably want to write a helper
function that takes in a lexer and a port and returns a list of tokens
and then go from there. There is one such here (the lex function):

https://github.com/racket/syntax-color/blob/master/syntax-color-test/tests/syntax-color/module-lexer.rkt

For just running examples and looking at their output, a simpler way
is probably to use codeblock-pict from the pict/code library. That
requires you to set up your lexer as a module lexer, but doesn't have
the disadvantage that you have to restart DrRacket to see changes,
just Running again will show the new results.

Robby



On Fri, Oct 7, 2016 at 10:30 AM, Matthew Butterick <m...@mbtype.com> wrote:
> 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.

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