Skip to content

feat: grammar coloring engine layer — roles, defaults, optional Labeled (#467 #342)#479

Open
SJrX wants to merge 1 commit into
issue-345-9from
issue-345-10
Open

feat: grammar coloring engine layer — roles, defaults, optional Labeled (#467 #342)#479
SJrX wants to merge 1 commit into
issue-345-9from
issue-345-10

Conversation

@SJrX

@SJrX SJrX commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What

The (pure, IntelliJ-free) substrate for grammar-based syntax coloring. Coloring is automatic with no grammar changes, and an optional wrapper handles the composite-span case you flagged (an IP address should be one literal, not per-octet).

Stacked on #478 (issue-345-9). This is the engine half; the IntelliJ annotator + color-settings page come next.

Design (per discussion)

  • Role { ENUM, LITERAL, OPERATOR, IDENTIFIER } + Region(start, end, role).
  • defaultRole(terminal) — colors everything automatically, zero grammar edits:
    • IntegerTerminalLITERAL
    • LiteralChoiceTerminal / FlexibleLiteralChoiceTerminalENUM, or OPERATOR when all choices are punctuation (:, +, =, ~, /, …)
    • RegexTerminalIDENTIFIER
    • whitespace / other → uncolored
  • Labeled(role, inner) — optional and transparent: SyntacticMatch/SemanticMatch/parse matching is delegated to inner, so wrapping affects only color, never validation/completion. Labeled(LITERAL, IPV4_ADDR) paints 127.0.0.1 as one literal. (Used sparingly; no mass rewrite.)
  • colorize(value) — labeled regions win; tokens outside any labeled region get their terminal's default role. Parse gained a defaulted regions field that the merging combinators thread.

The role → actual color mapping is intentionally deferred to the IntelliJ layer (next MR), so we can tune colors without touching the engine.

Tests

ColoringTest: default roles; the unchanged RestrictAddressFamilies grammar colors as ~→OPERATOR, families→ENUM, whitespace uncolored; Labeled collapsing an IPv4 address to one LITERAL; and Labeled being transparent to validation.

Open for the next MR

  • Role→TextAttributesKey mapping + ColorSettingsPage + the flag-gated annotator.
  • Which grammars (if any) to wrap in Labeled — likely just IP addresses to start. (MAC/CIDR / left to defaults unless we decide otherwise.)

Refs #467 #342

🤖 Generated with Claude Code

…ed (#467 #342)

Adds the (pure, IntelliJ-free) substrate for grammar-based syntax coloring. Coloring
is automatic and needs NO grammar changes; an optional wrapper handles composite spans.

- Role { ENUM, LITERAL, OPERATOR, IDENTIFIER } + Region(start, end, role).
- defaultRole(terminal): IntegerTerminal -> LITERAL; Literal/FlexibleLiteralChoice ->
  ENUM, or OPERATOR when all choices are punctuation (":", "+", "=", "~", "/", ...);
  RegexTerminal -> IDENTIFIER; whitespace/other -> uncoloured.
- Labeled(role, inner): optional, transparent wrapper. Matching is delegated to inner
  unchanged (SyntacticMatch/SemanticMatch/parse), so it affects only colour — e.g.
  Labeled(LITERAL, IPV4_ADDR) paints 127.0.0.1 as one literal instead of per-octet.
- Parse gains a defaulted `regions` field; the merging combinators (Seq, ZeroOrMore,
  OneOrMore, Repeat) thread it. colorize(value) returns labeled regions plus per-token
  defaults for anything not inside a labeled region.

Role -> TextAttributes mapping is deliberately left to the IntelliJ layer (next MR:
annotator + color settings, behind the experimental flag).

Tests: default roles; automatic colouring of the unchanged RestrictAddressFamilies
grammar (operator/enum, whitespace uncoloured); Labeled collapsing an IPv4 address to
one LITERAL; and Labeled being transparent to validation.

Refs #467 #342

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

1 138 tests  +4   1 138 ✅ +4   50s ⏱️ -1s
  302 suites +1       0 💤 ±0 
  302 files   +1       0 ❌ ±0 

Results for commit 5fb3d64. ± Comparison against base commit cbbfef2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant