tree-sitter-svg-paint
v0.2.0
Published
SVG paint/color sub-grammar for Tree-sitter, injected into paint attribute values by tree-sitter-svg
Maintainers
Readme
tree-sitter-svg-paint
A Tree-sitter grammar for SVG paint and color values — fill, stroke,
stop-color, color, and related properties — built against SVG2 painting
and CSS Color.
[!IMPORTANT] Pre-1.0 (
0.x): the grammar and CST shape are still evolving and subject to breaking changes between releases.
What This Parses
Only paint/color value strings. It is injected into tree-sitter-svg over
the paint attribute values (see that grammar's queries/injections.scm); the
host keeps the value as one opaque payload token and this grammar resolves it
into typed color nodes:
fill="url(#grad) rgb(255 0 0)"
paint_server url(#grad) fallback rgb_colorCovers paint servers (url(...) with keyword/color fallback), named colors,
#hex, and the CSS color functions rgb/rgba, hsl/hsla, hwb, lab,
lch, oklab, oklch, color(), and color-mix(). color_value is a
supertype, so a single (color_value) capture matches every color kind while
the concrete node still appears directly in the tree.
The standalone grammar declares a conflicts pair on paint_server so a
trailing separator parses without the host's closing quote.
Development
tree-sitter generate # regenerate src/parser.c from grammar.js
tree-sitter test # corpus + tag/highlight tests
bun run test # node binding + drift-guard testsconstants.js exports the color-space/hue-interpolation token sets;
grammar.test.ts asserts them against the shared catalog to prevent drift.
License
MIT or Apache-2.0 © Kaj Kowalski
