Skip to content

Syntax Highlighting

Stephan Max edited this page Sep 24, 2025 · 1 revision

Syntax highlighting is fueled by a mode’s keywords.txt file. Possible tokens can be found in Token.java. This page sheds light on how keywords have been created. Currently, this is a manual process, that will be replaced by a proper Gradle task if time permits.

Keyword creation is inspired by the p5.js web editor. Unless otherwise specified, the source for keywords is the p5.js reference JSON. The shell commands to obtain keywords are listed below.

p5 Constants

LITERAL2. Keywords are all names of the Constants module.

curl https://p5js.org/reference/data.json | jq -r '.classitems[] | select(.module=="Constants") | .name+" LITERAL2"' | sort | uniq

JavaScript Keywords

KEYWORD1. Extracted from Codemirror, the editor library that is also used by the p5.js web editor. Please note that this does not include some of the Foundation keywords of p5.js: Number, console, Object, Array, String, Boolean.

JavaScript Keywords for Flow Control

KEYWORD3. Manually selected: catch, do, else, for, if, switch, try, while.

p5.js Fields

KEYWORD2. All reference items with itemtype of property and a class different from p5. Also exclude modules Constants (covered above) and Foundation (JavaScript keywords).

curl https://p5js.org/reference/data.json | jq -r '.classitems[] | select(.module != "Constants" and .module != "Foundation" and .class != "p5" and .itemtype == "property") | .name + " KEYWORD2"' | sort | uniq

p5.js Variables

KEYWORD4. Same as above, but with class equal to p5.

url https://p5js.org/reference/data.json | jq -r '.classitems[] | select(.module != "Constants" and .module != "Foundation" and .class == "p5" and .itemtype == "property") | .name + " KEYWORD4"' | sort | uniq

p5.js Functions

FUNCTION1. All reference items with itemtype of method and class equal to p5.

curl https://p5js.org/reference/data.json | jq -r '.classitems[] | select(.itemtype == "method" and .class == "p5") as $methods | .name + " FUNCTION1"' | sort | uniq

p5.js Methods

FUNCTION2. Same as above, but with a class different from p5.

curl https://p5js.org/reference/data.json | jq -r '.classitems[] | select(.itemtype == "method" and .class != "p5") as $methods | .name + " FUNCTION2"' | sort | uniq

p5.js Built-Ins

FUNCTION3. For example, setup() or mouseDragged(). These functions are not distinguishable from other methods above based only on properties in the reference JSON. Currently, they have to be manually selected. An automated selection could check the examples for a string like function <name>. Will implement if time allows.

Clone this wiki locally