DSL coloring question

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.

1 Like

I did find this ticket.

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

See 1 Tool support for #lang-based Languages about the general mechanism of a lang supplying a "get-info" procedure.

The first subsection is about syntax coloring. You'll need to chase a link to the start-colorer 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?

1 Like

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?

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.

1 Like

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

and continue here: rhombus/rhombus-lib/rhombus/private/syntax-color.rkt at eb600b73f8004f591a49ba25511fcdba568d126c · racket/rhombus · GitHub

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.

1 Like