feat: grammar coloring engine layer — roles, defaults, optional Labeled (#467 #342)#479
Open
SJrX wants to merge 1 commit into
Open
feat: grammar coloring engine layer — roles, defaults, optional Labeled (#467 #342)#479SJrX wants to merge 1 commit into
SJrX wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).
Design (per discussion)
Role { ENUM, LITERAL, OPERATOR, IDENTIFIER }+Region(start, end, role).defaultRole(terminal)— colors everything automatically, zero grammar edits:IntegerTerminal→LITERALLiteralChoiceTerminal/FlexibleLiteralChoiceTerminal→ENUM, orOPERATORwhen all choices are punctuation (:,+,=,~,/, …)RegexTerminal→IDENTIFIERLabeled(role, inner)— optional and transparent:SyntacticMatch/SemanticMatch/parsematching is delegated toinner, so wrapping affects only color, never validation/completion.Labeled(LITERAL, IPV4_ADDR)paints127.0.0.1as one literal. (Used sparingly; no mass rewrite.)colorize(value)— labeled regions win; tokens outside any labeled region get their terminal's default role.Parsegained a defaultedregionsfield 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 unchangedRestrictAddressFamiliesgrammar colors as~→OPERATOR, families→ENUM, whitespace uncolored;Labeledcollapsing an IPv4 address to oneLITERAL; andLabeledbeing transparent to validation.Open for the next MR
TextAttributesKeymapping +ColorSettingsPage+ the flag-gated annotator.Labeled— likely just IP addresses to start. (MAC/CIDR/left to defaults unless we decide otherwise.)Refs #467 #342
🤖 Generated with Claude Code