A tree-sitter grammar for Processing (C++ mode) — .pde sketches that target processing.cpp.
Extends tree-sitter-cpp with Processing-specific syntax.
| Feature | Details |
|---|---|
color pseudo-type |
First-class type keyword, also usable as a variable name |
| Processing types | PVector, PImage, PGraphics, PFont, PShape, PShader, ArrayList, HashMap, and more — tagged as processing_type nodes |
| Processing built-in variables | width, height, mouseX, mouseY, frameCount, etc. — tagged as processing_builtin_variable |
| Processing constants | PI, TWO_PI, HALF_PI, P2D, P3D, LEFT, RIGHT, CENTER, etc. — tagged as processing_constant |
Optional class trailing ; |
class Ball { ... } without a semicolon is valid (matches real .pde files) |
.pde file type |
Grammar scope is source.pde, injection regex matches pde and processing |
| Lifecycle function highlighting | setup, draw, mousePressed, etc. highlighted as @function.builtin |
| Full query suite | highlights.scm, locals.scm, tags.scm tuned for Processing sketches |
- Fork this repo on GitHub under your account.
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/tree-sitter-processing-cpp.git cd tree-sitter-processing-cpp - Install dependencies:
npm install
- Generate the parser from the grammar:
npx tree-sitter generate
- Run the corpus tests:
npx tree-sitter test
npx tree-sitter parse path/to/your/sketch.pdePlay with the grammar in the browser:
npm start # opens tree-sitter playground at localhost:portThe Processing IDE (CppMode) uses this grammar for:
- Syntax highlighting — via
queries/highlights.scm - Go-to-definition / symbol outline — via
queries/tags.scm - Variable scope tracking — via
queries/locals.scm
In CppMode.java, load the grammar via the tree-sitter Java bindings:
// Using the tree-sitter Java bindings (ch.usi.si.seart:java-tree-sitter or similar)
Language processingCpp = Language.load("tree_sitter_processing_cpp");
Parser parser = new Parser();
parser.setLanguage(processingCpp);
Tree tree = parser.parseString(sketchSource);The parser is built as a .wasm for the IDE's web-based playground:
npx tree-sitter build --wasmcolor is added to primitive_type, matching the Java parser's PSEUDO_TYPE_KEYWORDS_USABLE_AS_NAMES set. This means color c = red; and Vec3 color; (using color as a field name) both parse correctly.
Real .pde files regularly write class Ball { ... } without the trailing ; that strict C++ requires. This grammar overrides _empty_declaration to accept a class/struct/union specifier with a body and no terminating semicolon. Forward declarations (struct Foo;) still require the semicolon.
processing_builtin_variable, processing_constant, and processing_type are distinct node types (not just identifier aliases) so query authors can match them precisely without fragile string-matching against identifier text.
Based on tree-sitter-cpp — MIT licensed. Processing extensions by Jose Gonzalez Llamas.