# DSL coloring question

**URL:** https://racket.discourse.group/t/dsl-coloring-question/3970
**Category:** Questions & Answers
**Created:** [October 14, 2025, 11:17pm UTC](https://racket.discourse.group/t/dsl-coloring-question/3970 "2025-10-14T23:17:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)
#### Post date: [October 14, 2025, 11:17pm UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/1 "2025-10-14T23:17:51Z")

</div>

I'm trying to create a DSL (for AP Comp Sci Principles' Pseudocode) and would like a few more categories for the syntax colorer. Are those permanently fixed such that they can't be changed? If so, is there a way to load color preference into DrRacket when you specify the language? Currently, `Symbol` and `Keyword` are the same, as are `String`, `Text`, and `Constant`. If I could change those, I might be able to get by with the provided color types. (Although I'm wondering if the docs are out of date, since they only have `'string` and `'constant`, but not `'text` as a possible value for the token type.

---

<div class="post-metadata">

### Author: ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)
#### Post date: [October 14, 2025, 11:20pm UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/2 "2025-10-14T23:20:29Z")

</div>

I did find this ticket.

> <https://github.com/racket/drracket/issues/380>
>
> https://github.com/racket/drracket/blob/7ae87809bc2e7d5849f27dd3689f837cd4c7ade9…/drracket/scribblings/tools/lang-tools.scrbl#L62-L72
> 
> \`(map first (racket:get-color-prefs-table))\` shows \`'text\` and \`'hash-colon-keyword\` are missing, which if included match the ten that have entries in the “Color / Racket” preferences tab. That table is hard-coded (and the preferences tab derived from it) : https://github.com/racket/gui/blob/0fbbf759d3f244458378a639f653971fdff76668/gui-lib/framework/private/racket.rkt#L294
> 
> An \`'sexp-comment\` token (a parsed “#;” in the racket lexer) is also styled, as a \`'comment\` : https://github.com/racket/gui/blob/0fbbf759d3f244458378a639f653971fdff76668/gui-lib/framework/private/racket.rkt#L335-L349
> 
> A \`'white-space\` token is styled as \`'parenthesis\`, which presumably has no visible effect if the lexer only produces that for invisible lexemes with invisible glyphs. Not changing styles at the boundary is to reduce memory usage : https://github.com/racket/gui/commit/2da0f724923b300ab98a508018604f7d71863d62
> 
> Some \`'symbol\` tokens get translated to \`'keyword\` tokens based on the “Editing / Indenting” prefs, which affects their coloring : https://github.com/racket/gui/blob/0fbbf759d3f244458378a639f653971fdff76668/gui-lib/framework/private/racket.rkt#L1376-L1431

So I guess my question is now, is there a way to load preferences with a `#lang` declaration.

---

<div class="post-metadata">

### Author: ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)
#### Post date: [October 15, 2025, 11:51am UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/3 "2025-10-15T11:51:54Z")

</div>

See [1&nbsp;Tool support for #lang-based Languages](https://docs.racket-lang.org/tools/lang-languages-customization.html) about the general mechanism of a lang supplying a "get-info" procedure.

The first subsection is about [syntax coloring](https://docs.racket-lang.org/tools/lang-languages-customization.html#%28part._.Syntax_.Coloring%29). You'll need to chase a link to the [start-colorer](https://docs.racket-lang.org/framework/Color.html#%28meth._%28%28%28lib._framework%2Fmain..rkt%29._color~3atext~3c~25~3e%29._start-colorer%29%29) method of `color:text<%>`.

Although I've only _used_ these via `get-info` in a tool (Emacs), not _implemented_ one for a lang, I think the hand-wavy summary is you can wrap and reuse the lexer you probably already wrote for your lang, to supply the coloring tokens to tools?

---

<div class="post-metadata">

### Author: ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)
#### Post date: [October 17, 2025, 12:08am UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/4 "2025-10-17T00:08:46Z")

</div>

Yeah. I've set up the coloring, but I wanted more colors than are available, since the default color scheme sets some of the colors to the same. Is there any way to load new color preferences based on the #lang chosen, or do I have to just tell my students to go in and change some colors?

---

<div class="post-metadata">

### Author: ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)
#### Post date: [October 17, 2025, 12:21am UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/5 "2025-10-17T00:21:24Z")

</div>

My understanding is that the set of symbols (for the token "type") returned by the lang's lexer is open -- it's not limited to those for the `#lang racket` lexer, for example.

Furthermore, instead of returning a symbol, the lexer can can return a hash-table with a `'type` mapping... as well as any other mappings it wants to. (Some of these extra mappings are motivated by `#lang rhombus`, and I know some of them ad hoc. I don't know if/when some might get "promoted" to be documented as "official" or "recommended" to use for other langs with similar characteristics?)

As for what token types get mapped to what colors, that's left up to each tool, such as DrRacket.

---

<div class="post-metadata">

### Author: ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)
#### Post date: [October 17, 2025, 1:15pm UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/6 "2025-10-17T13:15:44Z")

</div>

p.s. To discover more, I suppose you could look at what `rhombus` does for its `color-lexer`.

That chain seems to start here: [rhombus/rhombus-lib/rhombus/private/core.rkt at eb600b73f8004f591a49ba25511fcdba568d126c · racket/rhombus · GitHub](https://github.com/racket/rhombus/blob/eb600b73f8004f591a49ba25511fcdba568d126c/rhombus-lib/rhombus/private/core.rkt#L18)

and continue here: [rhombus/rhombus-lib/rhombus/private/syntax-color.rkt at eb600b73f8004f591a49ba25511fcdba568d126c · racket/rhombus · GitHub](https://github.com/racket/rhombus/blob/eb600b73f8004f591a49ba25511fcdba568d126c/rhombus-lib/rhombus/private/syntax-color.rkt)

You could get a sense for its variety of token types (and maybe some other interesting details?).

Then, you could open DrRacket and discover what kind of UI is provided for configuring them to be various colors.

* * *

Apologies if none of this is exactly on point. Hopefully someone else can chime in.

---

<div class="post-metadata">

### Author: ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)
#### Post date: [October 28, 2025, 12:53pm UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/7 "2025-10-28T12:53:52Z")

</div>

This is helpful. I was able to get a sufficient number of colored types, but without a way to provide a default color scheme, several of them end up the same color. I suppose I could create my own color scheme and provide instructions for how to use it.

---

<div class="post-metadata">

### Author: ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)
#### Post date: [October 28, 2025, 4:29pm UTC](https://racket.discourse.group/t/dsl-coloring-question/3970/8 "2025-10-28T16:29:45Z")

</div>

It's an interesting problem.

On the one hand, as you say, a lang may want distinct colors for distinct token types.

On the other hand, the lang probably shouldn't supply an exact color, because doing so shades off (pun) into the responsibility of themes. If a lang supplies some literal color, it could look bad or even be unreadable in certain themes. There needs to be some level of indirection.

* * *

Spitballing, two ideas:

1. Simplest: Tools like DrRacket and Racket Mode for Emacs could let users/themes pick some distinct color for "all other" token types. Although this might help the novel tokens stand out from "typical" ones -- a sort of, "hey, configure me!" signal -- the novel ones would default to all looking like each other. So not ideal.

2. Building on a concept from e.g. Emacs, where a "face" (~= font + attributes) can "inherit" plus modify some other face: There could be some little DSL for saying things like, "The `foo` token should look like the `symbol` (or `string` or whatever) token, except bold (or italic, underlined, lighter, darker, whatever)".

Probably there's some third, better idea?
